Forum Moderators: coopster
Problem is that if the user cancels the download the cleanup operation at the end of my script doesnt run - this will lead to problems later on as the next time that i create a zip that has the same filename as one that hasnt been cleaned up, instead of creating a new zip files will just be added to the one that is already on the server and not been deleted.
How do i handle the cancellation of a forced file download so that i can cleanup images / zips if they do this?
Here is a snip of my code.
for(all of my created jpegs){
$myFiles[] = "design".$des_num."_template".$t_ID.".jpg";
}
$execStr = "zip myZipFile.zip " . implode(" ", $myFiles);
exec($execStr);
$handle = fopen("myZipFile.zip", "r");
$contents = fread($handle, filesize("myZipFile.zip"));
fclose($handle);
//present the zip
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=myZipFile.zip;" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("myZipFile.zip"));
//echo out data
echo $contents;
foreach($myFiles as $key => $value){
unlink("/root/to/file/".$value);
}
//delete the zip
unlink("myZipFile.zip");
Cheers
Ally
[edited by: Scally_Ally at 9:53 am (utc) on May 24, 2007]
It would only work in a specific scenario but it is something to think about.
javascript
if(window.event == cancel button)
redirect= remove.php?filename=var file name
PHP
Get var file name,
unlink from the server
Also if you could post your complete code then we might give you a quick fix for it because i am assuming if user accepts to download you call a script in headers or whatever to pick the file from the server so must be using IF somewhere in the ELSE of that IF you can use remove.php code :)