Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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 Readfile()已开始在第页上显示_Php_Readfile_Ziparchive - Fatal编程技术网

Php Readfile()已开始在第页上显示

Php Readfile()已开始在第页上显示,php,readfile,ziparchive,Php,Readfile,Ziparchive,正在显示的部分内容: PKd�wL��� ���/images/image_0.jpg��ex\K� �1昙�3�133���;ffff����Ԇ�����w�̼߳�cw��딎�$��Z�������&QRTB�|>��E��M5���|�~b��)�o�3�� �>s���o�'���^B�O��V ����@���Q?S#(�� 6���v4���8����vvV�sy}#�_ �O��s�o���L�7Fv.F&�ol��WV.V��?����

正在显示的部分内容:

    PKd�wL��� ���/images/image_0.jpg��ex\K��1昙�3�133���;ffff����Ԇ�����w�̼߳�cw��딎�$��Z�������&QRTB�|>��E��M5���|�~b��)�o�3�� �>s���o�'���^B�O��V ����@���Q?S#(�� 6���v4���8����vvV�sy}#�_ �O��s�o���L�7Fv.F&�ol��WV.V��?�����g�W!�/w!�������K�oLL�1`���G�p�X���T�>C�@��L��)q���s��3�g�8�p�O�?
我正在尝试将图像下载到zip文件中,这是我目前得到的:

if (count($headers->images) > 0) {
    $counter = 0;
    $zip = new ZipArchive();
    $tmpFile = "tmpFolder/tmp" . strtotime("now") . ".zip";
    $zip->open($tmpFile, ZipArchive::CREATE);
    foreach($headers->images as $key => $images) $zip->addFromString("/images/image_" . $counter++ . ".jpg", file_get_contents($images));
    $zip->close();
    if (file_exists($tmpFile)) {
        $fname = basename($_POST["titleZipFile"] . ".zip");
        $size = filesize($tmpFile);
        header("Content-Type: archive/zip");
        header("Content-Disposition: attachment; filename=$fname");
        header("Content-Length: " . $size);
        ob_end_clean();
        readfile($tmpFile);
        //unlink($tmpFile);
        echo "<div id='reportMessage'><p>You have successfully save images. Please go to your folder " . $_POST["titleZipFile"] . ".zip<p></div>";
    }
}
if(计数($headers->images)>0){
$counter=0;
$zip=新的ZipArchive();
$tmpFile=“tmpFolder/tmp”.strotime(“现在”)。.zip”;
$zip->open($tmpFile,ZipArchive::CREATE);
foreach($headers->images as$key=>$images)$zip->addFromString(“/images/image”..$counter++..jpg”,file\u get\u contents($images));
$zip->close();
如果(文件_存在($tmpFile)){
$fname=basename($_POST[“titleZipFile”]。.zip”);
$size=filesize($tmpFile);
标题(“内容类型:存档/zip”);
标题(“内容处置:附件;文件名=$fname”);
标题(“内容长度:.$size”);
ob_end_clean();
readfile($tmpFile);
//取消链接($tmpFile);
echo“您已成功保存图像。请转到您的文件夹“$\u POST[“titleZipFile”]”。zip”;
}
}
如果我删除取消链接($tmpFile);第二行,tmp zip实际上是生成的,并且在zip中有图像。然而,它实际上并没有在浏览器中显示zip下载


有人知道为什么会这样吗

尝试将内容类型的标题更改为以下内容。我认为标题导致浏览器在解释它应该做什么时出现问题。尝试以下类型

 header('Content-type: application/zip');

为什么不直接将它们重定向到zip文件路径并让浏览器处理它?@KaffineAddict会自动在浏览器中下载zip吗?是的,我相信会,但我还有一个选择。看起来你试图同时输出二进制文件和html?你不能同时做到这两个