[英]How to display image on codeigniter that is stored in oracle database as BLOB type?
I am trying to display an image that is stored in oracle DB as BLOB data-type. 我试图显示以BLOB数据类型存储在oracle DB中的图像。 this is my MODEL code 这是我的MODEL代码
function viewblobData() {
$user = $this->session->userdata('user_logged_in');
$returnLobValue = '';
if (!empty($user)) {
$conn = $this->db->conn_id;
$sql = "SELECT * FROM OP_REG_IMAGE WHERE REG_NO = '$user'";
$stmt = oci_parse($conn, $sql);
oci_execute($stmt)
or die("Unable to execute query<br/>");
while ($row = oci_fetch_assoc($stmt)) {
$returnLobValue = $row['PAT_IMAGE']->load();
header("Content-type: image/jpg");
}
}
return $returnLobValue;
}
and this is for display at view 这是在视图中显示
<?php echo $this->MY_MODEL->viewblobData(); ?>
But its shows "the image http://localhost/.....
cannot be displayed because it contains errors" 但是它显示“图像http://localhost/.....
无法显示,因为它包含错误”
if I remove the line header("Content-type: image/jpg");
如果我删除行header("Content-type: image/jpg");
then it shows like below whole page: 然后显示如下整个页面:
�M�t9UYG�G��d���~��5 �V�W��jժ�I�P��l6;��Po�ߖ�]��o�_���v��]o7{���Xr?_� ��bp��F3�s>ߙ�K)��f_�w��9����Z#���i�:�V�Y�h�=�����o���{��px=����o��fk���:>����~u�=��w��~9������y�]^����ٹ_���
Can anyone help? 有人可以帮忙吗?
You can use the image libraries:- eg 您可以使用图片库:-例如
$img = imagecreatefromstring($row['PAT_IMAGE']);
if ($img !== false) {
$image_new_name = 'sig_' . time() . '.png';
$image_path = 'upload/' . $image_new_name;
$image_name = $ROOT_DIR . '/' . $image_path;
if (!file_exists($image_name)) {
imagepng($img, $image_name);
imagedestroy($img);
} else {
$image_new_name = 'new_' . $image_new_name;
$image_path = 'upload/new_' . $image_new_name;
$image_name = $ROOT_DIR . '/' . $image_path;
imagepng($img, $image_name);
imagedestroy($img);
}
This code will generate image from your data to the provided dir
. 此代码将从您的数据生成图像到提供的dir
。 then use that image to display. 然后使用该图像进行显示。 enjoy. 请享用。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.