SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    0 Post(s)
    0 Thread(s)

    handle cancel download

    Hi All,
    I have a script that dynamically creates a bunch of hires jpegs and presents them to the user to download in a nice, easy, managable and lovely zip file (using exec command line function). When the user has downloaded the file all 'temp' images are then cleaned up and the zip file deleted so not to take up any space.
    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 " . implode(" ", $myFiles);

    $handle = fopen("", "r");
    $contents = fread($handle, filesize(""));

    //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;;" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize(""));
    //echo out data
    echo $contents;

    foreach($myFiles as $key => $value){
    //delete the zip


  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Philadephia, PA
    1 Post(s)
    0 Thread(s)
    If the zip file already exists (file_exists), delete it before you create it again.

    You can use the file creation or modification time to run a cleanup script on a regular interval as well.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts