1

我有 1 列包含二进制格式数据。我想在浏览器上显示该图像并且我正在使用 codeignater

我的模型代码

function GetLogoById($Id)
    {
        $this->load->database();
        $query =  $this->db->query( "EXEC GetLogoById '$Id'" );
        $result = array();
        foreach ($query->result() as $row)
        {
            $result[] = array("Logo"=> $row->Logo);
        }
           return $result;
    }

我的控制器代码:

public function GetLogoById()
    {
    $this->load->model('MyModel');
    $result = $this->MyModel->GetLogoById($Id);
    $result = base64_decode($result);

    echo $result;
}

空白的在浏览中返回。我错过了什么......

4

3 回答 3

1

试试这个。

$this->load->model('GetLogoById');

   $result = $this->mymodel->GetLogoById($CarrierId);

   header('Content-type: image/png');
   echo  $result[0]['Logo'];
于 2013-10-04T12:01:13.517 回答
0

尝试这个:

public function GetLogoById()
{
$this->load->model('MyModel');
$result = $this->MyModel->GetLogoById($Id);
//$result = base64_decode($result);
header('Content-Type: image/jpeg');  #set a header
echo $result;
}
于 2013-10-04T10:09:04.223 回答
0
<?php

public function GetLogoById() {

   $this->load->model('MyModel');

   // Get your result
   $result = $this->MyModel->GetLogoById($Id);

   // Do base64 decode if you encoded it.
   $result = base64_decode($result);

   // Set header according to the image type. 
   // if the image is jpg use 'image/jpeg'
   // if the image is png use 'image/png' 
   // and so on ...
   header('Content-Type: image/jpeg');

   // Only echo the exact value. Keep in mind that no other 
   // space or any other values are echoed
   echo $result;

   // Also make sure that there must not be any spaces or other values before or after the php tags
}

?>

// 这是一个示例。

<?php

   $image_data = file_get_contents( __DIR__ .  '/dino_babu.jpg');

   $image_token = base64_encode($image_data); // Save this token to database

   $image_data_decode = base64_decode($image_token); // retrieve the token & decode it

   header('Content-Type: image/jpeg'); // Set the header

   echo $image_data_decode; // Print the data

?>
于 2013-10-04T10:49:49.523 回答