怎么用Yii2.0的response发送自己的http头? [ 2.0 版本 ]
Yii::$app->response->content = file_get_contents($file);
Yii::$app->response->headers->set('Content-Type', \yii\helpers\FileHelper::getMimeType($file));
Yii::$app->response->send();
Yii::$app->end();
这个头根本就没有发送出去,还是Content-Type:text/html ; charset=utf-8
。
到底怎么发啊?
我搞定了,http://stackoverflow.com/questions/27799649/yii2-how-to-response-image-and-let-browser-show-it
我要的效果不是下载,是要下载的话直接Response有自带函数!
是要浏览器直接显示图片:
Yii::$app->response->sendFile($file, null, ['inline' => true]);
Yii::$app->end();
像上面这样就可以了!
共 2 个回答
-
chocoboxxf 回答于 2015-08-26 18:08 举报
可以试试看用
Yii::$app->response->sendFile($file, '下载文件名');
代替你的写法共 1 条回复 -
sevenyearsold 回答于 2015-08-27 09:08 举报
Yii::$app->response->format = Response::FORMAT_RAW;
设置编码为图片,下面直接ruturn你的图片就可以了;jayrui612 觉得很赞
dyllen
注册时间:2014-09-09
最后登录:2020-10-16
在线时长:48小时47分
最后登录:2020-10-16
在线时长:48小时47分
- 粉丝8
- 金钱400
- 威望80
- 积分1680