我有以下脚本将图像输出到浏览器,效果很好。
$file_to_output=$_SERVER['DOCUMENT_ROOT'].'/static/imgs/uploads/20110318172207_16.jpg';
header('Content-Type: image/jpeg');
$raw=imagecreatefromjpeg($file_to_output);
// Output the image
imagejpeg($raw);
// Free up memory
imagedestroy($raw);
当我将完全相同的代码放入视图中时,它不再起作用并给出一堆像这样的奇怪字符:
����JFIF��>CREATOR:gd-jpeg v1.0(使用 IJG JPEG v62),默认质量 ��C
我需要做什么才能使其在视图中工作?
你不应该把它放到视图中。所有视图输出都会被缓冲,稍后通过 Response 对象返回。
这就是所有响应逻辑,所以你的action代码应如下所示:
$path = DOCROOT.'static/imgs/uploads/20110318172207_16.jpg';
$this->response->headers('content-type',File::mime($path))
->body(file_get_contents($path));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)