我知道这个问题在这个论坛发布了很多次,但相信我我已经尝试了所有可能的解决方案建议,但它并没有为我工作。ZIP文件下载php读取文件()错误
我试图下载使用压缩多个文件,但zip文件被下载的成功,它的腐败,我在记事本打开它后遇到错误:
警告:ReadFile的(E:\下载/ IMG -20140831-WA0000.zip)[function.readfile]:未能打开流:在...
我尝试了所有在论坛中提到的可能的解决方案,如头检查没有这样的文件或目录,网页服务器用户对我创建ZIP文件的文件夹具有写入权限,下载前进行错误检查等,但它没有任何问题d出来。
进行错误检查后,我遇到了类似
错误创建ZIP文件:IMG-20140831-WA0000.zip
我的代码片段:
function zipFilesDownload($file_names, $archive_file_name, $file_path) {
$zip = new ZipArchive;
if ($zip->open($archive_file_name, ZipArchive::CREATE) !== TRUE) {
exit("cannot open <$archive_file_name>\n");
}
foreach($file_names as $files) {
$zip->addFile($file_path . $files, $files);
}
if ($zip->close() === false) {
exit("Error creating ZIP file : " . $archive_file_name);
}
if (file_exists($archive_file_name)) {
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . $archive_file_name . "");
header("Pragma: no-cache");
header("Expires: 0");
readfile("E:\Downloads/" . $archive_file_name);
ob_clean();
flush();
exit;
} else {
exit("Could not find Zip file to download");
}
}
$fileNames = array(
'D:\\xampp\htdocs\BE\Multimedia/' . $fullName,
'D:\\xampp\htdocs\BE\Decrypt/' . $decrypt_file
);
$zip_file_name = $actualName . '.zip';
$file_path = dirname("E:\Downloads") . '/';
zipFilesDownload($fileNames, $zip_file_name, $file_path);
请建议一些解决方案
'目录名( “E:\下载”)''返回 “E:\”'。如果你不使用'dirname()'会发生什么? – 2015-04-05 07:37:02
另外,'$ actualName'从哪里来? – 2015-04-05 07:42:32
@SevrriMOslen'$ actualName'是要下载的zipFile的名称。例如。如果'$ actualName ='hello';'然后'$ zip_file_name = hello.zip' – 2015-04-05 15:09:50