简体   繁体   中英

PHP download multiple files as zip error

I tried to make an download button to zip my files. When I set multiple files in the array it gives the error 在此处输入图片说明

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\\n"; fwrite($file, $text); fclose($file); ?> 

试试这个变化:

$zipname =getcwd()'/file'.$random.'.zip';

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"]); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM