douhensheng1131 2019-01-26 00:47
浏览 527
已采纳

HTTP图像输出提供blob数据而不是图像

My url looks like ..../image/view?id=6

Navigating to this url should give an image from my database. But currently I'm getting a bunch of weird characters as a response.

When I output (see below) I'm seeing my image.

<img src="data:image/jpeg;base64,'.base64_encode( $image->Data ).'"/>

I'm using this piece of code to generate my HTTP response, but the response is just the blob data:

 header('Content-Type :'.$image->Extension);
 header('Content-Disposition: filename='.$image->Name.'.'.$image->Extension);
 header('Content-Length: ' . strlen($image->Data));
 $response->format = Response::FORMAT_RAW;
 $response->data = $image->Data;

Current output begins with:

����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v90), default quality ��C     $.' ",#(7),01444'9=82<.342��C     2!!22222222222222222222222222222222222222222222222222���"��    ���}!1AQa"q2���#B��R��$3br� 

Headers used:

   Accept-Ranges: bytes
   Cache-Control: private
   Content-Disposition: inline;        filename="FYdsl67l4PWJQ7QFFeo14Ena76gr0pEP.jpg"
   Content-Length: 320135
   Content-Type: image/jpeg
   Date: Mon, 28 Jan 2019 19:05:11 GMT
   Expires: 0
   Pragma: public
   Server: Microsoft-IIS/8.5
   X-Powered-By: PHP/5.6.24, ASP.NET

Any help would be appreciated

  • 写回答

3条回答 默认 最新

  • dsd119120 2019-04-03 09:55
    关注

    Issue has been fixed, seems that my file was in an incorrect encoding ... File needed to be iso instead of utf-8

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部