SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delaying File Download by x seconds?

    Hey,

    Been mulling over some code on here and found a snippet that was very very helpful in forcing downloads for files but I wanted to ask if there was anyway I could delay the download by x seconds.

    Here is the code:

    PHP Code:
    <?php 
    // downloading a file use [url=http://somewhere.com/download.php/?filename=name]http://somewhere.com/download.php/?filename=name[/url] of file 
     
    $fullpath ="/home/newdesign";
    $filename $_GET['filename']; 
     
    if(!
    $filename){ echo "ERROR: No filename specified. Please try again."; } 
    else { 
         
    // fix for IE catching or PHP bug issue 
    header("Pragma: public"); 
    header("Expires: 0"); // set expiration time 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    // browser must download file from server instead of cache 
     
    // force download dialog 
    header("Content-Type: application/force-download"); 
    header("Content-Type: application/octet-stream"); 
    header("Content-Type: application/download"); 
     
    // use the Content-Disposition header to supply a recommended filename and 
    // force the browser to display the save dialog. 
    header("Content-Disposition: attachment; filename=".basename($filename).";"); 
     
    header("Content-Transfer-Encoding: binary"); 
     
    $root_path "/home/public_html/newdesign/"
     
    $myfile $root_path $filename
     
    header("Content-Length: ".filesize($myfile)); 
     
    readfile("$myfile"); 
    exit(); 

    ?>
    It's just that I want a page to show "Your download will start in x seconds" instead of auto starting the download which is what happens at the moment so I want to delay the download. Any ideas?

    Cheers,
    Chris

  2. #2
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setting the Content-Type header 3 times just overwrites the previous entries, so really only the last one is getting sent to the browser.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sleep() worked a treat =) thanx


Bookmarks

Posting Permissions

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