在 Kohana 3.2 视图中输出图像
我有以下脚本将图像输出到浏览器,效果很好。
$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
我需要做什么才能使其在视图中工作?
I have the following script to output an image to the browser wich works fine.
$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);
when I put this exact same code in a view its doesn't work anymore and give a bunch of stange characters like this:
����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ��C
What do I have to do to make it work in a view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该将其放入视图中。所有视图输出都会被缓冲,稍后通过 Response 对象返回。
这是所有响应逻辑,因此您的操作代码应如下所示:
You're not supposed to put that into a view. All view output is buffered, being returned through a Response object later.
This is all response logics, so your action code should look like:
另一种方法是:
参见 Response#send_file
Another way would be:
see Response#send_file