我有這個PHP腳本運行,允許用戶下載一個zip文件中的圖像文件夾,這意味着創建zip文件並將其發送給用戶,然後從服務器上刪除它。它工作正常,但有時它不會刪除zip。有任何想法嗎?PHP腳本發送zip文件,並在不工作後刪除
$filename_no_ext=$_GET['zip'];
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
// zip the stuff (dir and all in there) into the tmp_zip file
`zip -r $tmp_zip $filename_no_ext`;
// calc the length of the zip. it is needed for the progress bar of the browser
$filesize = filesize($tmp_zip);
header("Content-Length: $filesize");
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
fclose($fp);
// clean up the tmp zip file
//`rm $tmp_zip `;
unlink($tmp_zip);
//If user aborts check they have and then clean up the zip
ignore_user_abort(true);
echo "\n";
if (connection_status()!=0){
unlink($tmp_zip);
}
if (connection_aborted()) {
unlink($tmp_zip);
}
任何幫助將是偉大的。
你可能想使用php zip類而不是Unix命令'zip',少跨平臺http://www.php.net/manual/en/book.zip.php –