我在Zend Framweork中使用php遇到问题,动态缩放图像以作为mime-type image / jpeg返回。
问题表现为firefox报告“无法显示图像,因为它包含错误”。这与在return dynamic image zf2
中报告的问题相同为了复制这个问题,我删除了任何文件IO并从类似的堆栈溢出示例中复制了代码verbatim(在zend FW动作控制器中):
$resp = $this->getRespose();
$myImage = imagecreate(200,200);
$myGray = imagecolorallocate($myImage, 204, 204, 204);
$myBlack = imagecolorallocate($myImage, 0, 0, 0);
imageline($myImage, 15, 35, 120, 60, $myBlack);
ob_start();
imagejpeg($myImage);
$img_string = ob_get_contents();
$scaledSize = ob_get_length();
ob_end_clean();
imagedestroy($myImage);
$resp->setContent($img_string);
$resp->getHeaders()->addHeaders(array(
'Content-Type' => $mediaObj->getMimeType(),
'Content-Transfer-Encoding' => 'binary'));
$resp->setStatusCode(Response::STATUS_CODE_200);
return $resp;
当我使用wget捕获jpeg响应时,我注意到'0A'作为输出的第一个字节而不是字段分隔符'FF'。缓冲区中捕获的数据中没有此类“0A”,响应的内容成员也没有。试图用GIMP打开wget输出失败,除非我删除了0A。我猜Zend FW正在使用换行作为响应字段与内容的字段分隔符,但我不确定这是否是问题,或者如果是,如何修复它。
我的回复字段看起来不错:
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Sat, 02 Jun 2018 23:30:09 GMT
Server: Apache/2.4.7 (Ubuntu) OpenSSL/1.0.1f
Set-Cookie: PHPSESSID=nsgk1o5au7ls4p5g6mr9kegoeg; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Transfer-Encoding: binary
Content-Length: 1887
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg
这是wget的前几个字节的转储,其中jpeg流失败了:
00000000 0a ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 | ....... JFIF ..... |
<00> 00000010 60 00 60 00 00 ff fe 00 3e 43 52 45 41 54 4f 52 |.
.....&gt; CREATOR |
知道'0A'来自哪里?我正在运行zend framework 2.5.1,PHP 7.2.2
答案 0 :(得分:0)
谢谢Tim Fountain。
我终于找到了我创建的一些教义实体中隐藏的违规文件。果然,一个流浪的“?&gt;”空行。
非常感谢