簡體   English   中英

PHP下載多個文件為zip錯誤

[英]PHP download multiple files as zip error

我試圖創建一個下載按鈕來壓縮我的文件。 當我在數組中設置多個文件時,出現錯誤 在此處輸入圖片說明

當我對“ files / path / to / 8717953176714.jpg”進行硬編碼時,它可以工作。

這是我的代碼:

 <?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';

問題是。 我把一個數組變成一個數組。 因此它沒有走上好路。

 $files = $_POST["foto"]; 

代替

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM