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

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>
    
    打赏 评论
  • duandgfh0506 2017-02-16 08:26

    try this change :

    $zipname =getcwd()'/file'.$random.'.zip';
    
    打赏 评论

相关推荐 更多相似问题