[英]PHP- ZipArchive 0 byte files
我正在嘗試將文件夾下載為 zip,但我總是得到一個包含 0 字節文件的 zip。 我嘗試了在互聯網上找到的所有解決方案,但沒有幫助。 這是代碼:
$files= scandir($dir);
$zip = new ZipArchive();
$tmp_file = tempnam('.','');
if ( $zip->open($tmp_file, ZipArchive::CREATE)===TRUE) {
# loop through each file
foreach($files as $file){
# download file
$download_file = file_get_contents($file);
#add it to the zip
$zip->addFromString(basename($file),$download_file);
}
# close zip
$zip->close();
# send the file to the browser as a download
header("Content-disposition: attachment; filename=$nome_dir.zip");
header("Content-length: " . filesize($tmp_file));
header('Content-type: application/zip');
readfile($tmp_file);
}
我不明白我哪里錯了
這可能與 PHP 中的內存分配問題有關,例如我的 PHP zip 函數使用了太多內存
另請檢查: https ://www.airpair.com/php/fatal-error-allowed-memory-size
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.