duanchi6377 2017-02-16 08:15
浏览 83
已采纳

PHP下载多个文件作为zip错误

I tried to make an download button to zip my files. When I set multiple files in the array it gives the error enter image description here

When I hardcode "files/path/to/8717953176714.jpg" it works.

Here is my code:

<?php

//print_r($_POST["foto"]);

$files = array($_POST["foto"]);
$random = rand(1000000000, 9999999999);
$zipname = 'file'.$random.'.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
    $zip->addFile($file);
}

$zip->close();

$filename = $zipname;

 header('Content-type: application/zip');
 header('Content-Disposition: attachment; filename="' . $filename . '"');
 header('Content-length: ' . filesize($filename));  
 readfile($filename);
 $file = fopen('iplog.txt', 'a', 1);
 $ipz = getenv("REMOTE_ADDR");
 $text = "$ipz
";
 fwrite($file, $text);
 fclose($file); 

?>

</div>
  • 写回答

2条回答 默认 最新

  • dongzha0813 2017-02-16 09:20
    关注

    The problem was. I made an array into an array. So it didn't get the good path.

    $files = $_POST["foto"];

    instead of

    $files = array($_POST["foto"]);

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 unitywebrequest分段下载导致报错,如何解决?
  • ¥15 错误使用 gretna_GUI_PreprocessInterface>RunBtn_Callback
  • ¥15 WPF如何用Chart绘画出Y轴的左边数据
  • ¥15 pycharm无法查看内置代码
  • ¥15 跑hls xfopencv的例程standalone_hls_axi_example出的错误,csim没问题,c synthesis出的错误
  • ¥15 sqlserver update语句逐行生效
  • ¥20 Windows10系统命令行调用
  • ¥15 php环境如何实现国密SM2相关功能
  • ¥15 关于#单片机#的问题:K210 例程里面提示我iomem.h: No such file or directory
  • ¥15 LSPI算法的大问题