日冰,
我有一个带有多个复选框的表单,它允许用户在提示下载zip文件之前选择他们想要的小册子。 zip档案下载功能正常运行。但我意识到下载会话将被终止而不下载整个文件(比如说8MB),并且下载的zip文件会被破坏。
参考下面的代码,它不能解决问题。任何人都可以建议我需要查看哪些设置,或者我是否错过了任何功能?
if($send) {
// Make sure program execution doesn't time out
// Set maximum script execution time in seconds (0 means no limit)
set_time_limit(0);
$post = $_POST;
$file_folder = "pdf/"; // folder to load files
$zip = new ZipArchive(); // Load zip library
$zip_name = "".time().".zip"; // Zip name
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Opening zip file to load files
$error .= "* Sorry ZIP creation failed at this time
";
}
foreach($post['brochure'] as $file){
$zip->addFile($file_folder.$file); // Adding files into zip
}
$zip->close();
if(file_exists($zip_name)){
// set headers push to download the zip
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header('Content-type: application/zip');
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
header("Content-Length: ".filesize($zip_name));
readfile($zip_name);
// remove zip file is exists in temp path
unlink($zip_name);
$fp = @fopen($zip_name, "rb");
if ($fp) {
while(!feof($fp)) {
print(fread($fp, 1024*8));
flush(); // this is essential for large downloads
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
}