Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图像发送到浏览器时会出现奇怪的交叉_Php_Image_Header - Fatal编程技术网

Php 图像发送到浏览器时会出现奇怪的交叉

Php 图像发送到浏览器时会出现奇怪的交叉,php,image,header,Php,Image,Header,我正在尝试向客户端发送图像,如下所示: public function saveAction() { if(!isset($_SESSION)) session_start(); if(isset($_SESSION['id'])) { $em = $this->getDoctrine()->getEntityManager(); $image = $em->getRepository('AcmeHomeBundle:

我正在尝试向客户端发送图像,如下所示:

public function saveAction()
{
    if(!isset($_SESSION)) session_start();

    if(isset($_SESSION['id'])) {    

        $em = $this->getDoctrine()->getEntityManager();
        $image = $em->getRepository('AcmeHomeBundle:Image')->find($_SESSION['id']);

        // open the file in a binary mode
        $fpass = fopen($image->getPath(), 'rb');

        header("Content-Type: image/".$image->getFormat());
        header("Content-Length: ".$image->getSize());
        header('Content-Disposition: attachment; filename="image.'.$image->getFormat().'"');

        // dump the picture and stop the script
        fpassthru($fpass);
        exit;
    }
}
但发送的图像有时会被裁剪。然而,原始图像是正确的。有什么可能出错的建议吗

以下是一个例子:

原始图像:

已发送图像:


这张照片似乎只下载了一半或发送了一半

看看内容大小是不是太小了?检查fpassthru的输出是否与图像大小匹配


检查日志中是否存在与时间或内存相关的错误

,以确保……该代码是否能够纠正该错误?第14行:
$imagen
而不是
$image
@Deryck-对不起,这是因为我的翻译让它更容易理解。编辑:看起来不像是庄稼。看起来这张照片要么没有完全发送,要么没有完全接收。你的网络标签告诉你什么?@h2ooooo-也许吧。知道吗?您在PHP中使用过“imageMagick”吗?size属性设置不正确。这导致浏览器假定文件大小不正确。谢谢@user1281385。是否有任何理由使用
标题(“内容长度:”.$image->getSize())。我会用这个属性来做这个。