Home  >  Article  >  Backend Development  >  在codeigniter框架的控制器中用header("Content-type: image/jpeg")输出图片怎么无法显示

在codeigniter框架的控制器中用header("Content-type: image/jpeg")输出图片怎么无法显示

WBOY
WBOYOriginal
2016-06-06 20:28:181919browse

我是这样写的:
ob_start();
$this->ImageResizeNew('D:/123.jpg', 240, 180);(这个输出图象函数没问题)
$imagevariable = ob_get_contents();
ob_end_clean();
header('Content-type: image/jpeg');
echo $imagevariable;
代码我在非CI框架中是可以正常显示图片的,但写在CI的控制器中就无法显示了,我在CI官方论坛中也提问过,但没有得到回复,希望这里有熟悉CI框架的朋友帮我解决下这个问题,不胜感激。
换成下面这段代码也不行
$pic_url = file_get_contents('D:/123.jpg');(图片路途没有问题)
header('Content-type: image/jpeg');
echo $pic_url;

回复内容:

我是这样写的:
ob_start();
$this->ImageResizeNew('D:/123.jpg', 240, 180);(这个输出图象函数没问题)
$imagevariable = ob_get_contents();
ob_end_clean();
header('Content-type: image/jpeg');
echo $imagevariable;
代码我在非CI框架中是可以正常显示图片的,但写在CI的控制器中就无法显示了,我在CI官方论坛中也提问过,但没有得到回复,希望这里有熟悉CI框架的朋友帮我解决下这个问题,不胜感激。
换成下面这段代码也不行
$pic_url = file_get_contents('D:/123.jpg');(图片路途没有问题)
header('Content-type: image/jpeg');
echo $pic_url;

在使用你的图像方法之前请先执行以下ob_clean去清空ob缓存,因为可能框架在你这个方法之前已经有内容输入到缓冲区了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn