output image in a Kohana 3.2 view

二次信任 提交于 2019-12-01 11:04:00

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:

$path = DOCROOT.'static/imgs/uploads/20110318172207_16.jpg';

$this->response->headers('content-type',File::mime($path))
    ->body(file_get_contents($path));

Another way would be:

$path = DOCROOT.'static/imgs/uploads/20110318172207_16.jpg';

// Send file as download
$this->response->send_file($path);

// Send file as inline
$this->response->send_file($path, NULL, array('attachment' => 'inline'));

// Another way to send as inline
$this->response->body(file_get_contents($path));
$this->response->send_file(TRUE, $path);

see Response#send_file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!