【发布时间】:2018-04-25 20:44:09
【问题描述】:
$this->autoRender = false;
$this->response->header("HTTP/1.1 200 OK");
$this->response->header("Pragma: public");
$this->response->header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
$this->response->header("Cache-Control: private", false);
//$this->response->header("Content-type: image/png"); //tried also
$this->response->type('jpg');
$this->response->body(readfile($file));
return $this->response;
总是返回 Content-Type: text/html;字符集=UTF-8。
谢谢
【问题讨论】:
-
内容类型不对,但是body本身呢?它是否包含您期望的图像?也许代码中还有另一个问题,而是生成了错误响应。那么是否有任何错误显示?你检查过日志文件吗?
-
日志中没有错误。 (蛋糕的临时日志,apache 都没有日志)图像正确显示,如果它们在页面内。但是,如果我在新选项卡(使用相同的链接)中打开图像,由于内容类型错误,图像不会显示为图像,而是显示为 ascci(我相信)表示(二进制的 scren 中的经典抛出)。有任何想法吗?我错过了一些步骤吗?
-
您在控制器中加载了哪些组件?
-
use MicrosoftAzure\Storage\Common\Internal\Resources; use MicrosoftAzure\Storage\File\FileRestProxy; use MicrosoftAzure\Storage\File\FileSharedAccessSignatureHelper; App::uses( 'AuthController', 'Controller' ); App::uses( 'Sanitize', 'Utility' );你是这个意思吗?谢谢 -
您是否尝试加载
RequestHandler组件以查看是否有帮助?
标签: php cakephp http-headers httpresponse cakephp-2.8