如何在存储在oracle数据库中的codeigniter上显示BLOB类型的图像


How to display image on codeigniter that is stored in oracle database as BLOB type?

我正在尝试将存储在oracle DB中的图像显示为BLOB数据类型。这是我的型号代码

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;
}

这是在视图中显示的

<?php echo $this->MY_MODEL->viewblobData(); ?>

但它显示"图像http://localhost/.....无法显示,因为它包含错误"

如果我删除header("Content-type: image/jpg");行,那么它会显示如下整个页面:

�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�]^����ٹ_���

有人能帮忙吗?

您可以使用图像库:例如

    $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);
            }

此代码将从您的数据生成图像到提供的dir。然后使用该图像进行显示。享受。:)