我需要从网站下载一个 zip 文件,因为我需要在一次下载中合并多个文件(最多 100 个单独的文件)。
尝试创建 zip 文件时,它会按预期下载,文件名也按预期以“YYYY.MM.DD - HH.MM.SS”格式显示。尝试在 Windows 7 (或 winzip)中打开 zip 文件时出现我的问题- 我收到以下错误消息。这种情况在多次尝试中反复发生。
我假设我在对 zip 文件的创建或下载进行编码时出错,而不是 zip 文件格式本身是一个问题,因为我可以打开不同的 zip 文件 - 谁能看到我可能犯的错误?(错误图像下方包含的代码)
我曾尝试使用 php作为参考,将下载多个文件作为 zip 文件。
//backup file name based on current date and time
$filename = date("Y.m.j - H.i.s");
//name of zip file used when downloading
$zipname = 'temp.zip';
//create new zip file
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
//yes, I know the zip file is empty currently - I've cut the code from here for
//now as the zip file doesn't function with / without it currently
$zip->close();
//download file from temporary file on server as '$filename.zip'
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$filename.'.zip');
header('Content-Length: ' . filesize($zipname));
readfile($zipname);