我有以下代码,这些代码在带有WinRAR的Windows上也能正常工作,在Mac上也能正常工作。但是,由于某种原因,当您使用默认的Windows资源管理器将其打开时,该压缩文件显示为空,并且右键单击并解压缩时,它表示无效。当使用winrar或在Mac上打开同一文件时,所有文件都在那里。有任何想法吗?
$passcode = $_GET['passcode'];
$zip = new ZipArchive;
$download = 'download_files_'.$passcode.'.zip';
$zip->open($download, ZipArchive::CREATE);
foreach (glob("../dashboard/uploads/".$passcode."/*.jpg") as $file) { /* Add appropriate path to read content of zip */
$zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename = $download");
header('Content-Length: ' . filesize($download));
header("Location: $download");
使用以下方法可以很容易地解决此问题:我必须将生成的zip文件移动到uploads文件夹内,然后删除../dashboard/uploads/
,因为正是该路径导致Windows认为它是损坏的文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句