SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automatic Download

    Like download.com; "Your download should start shortly, if it dosen't, click here" I need something like that. If this isn't PHP, can you direct me to a write-up to investigate. Cheers.

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think its done by sending headers. Two in this case. The first being the type of file and the second being the location of the file.

  3. #3
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the basic script i use:
    PHP Code:
    $path "path/to";
    $file "file.wmv";

    if (
    $file != '' && is_file(realpath("$path/$file"))) {
        if (
    $fp = @fopen("$path/$file""rb")) {
            
    header('Cache-Control: no-cache, must-revalidate'); 
            
    header('Pragma: no-cache'); 
            
    header("Content-type: application/force-download"); 
            
    header("Content-Disposition:attachment; filename=\"" $file "\""); 
            
    header("Content-length:" . (string)(filesize("$path/$file"))); 
            
    fpassthru($fp); 
            
    fclose($fp);
        } else {
            die (
    "Error:  the file could not be opened.");
        }
    } else {
        die (
    "Error:  the file could not be found.");

    one important thing (that's not in the above script) you will want to do is validate where $file and $path come from and what files are allowed to be downloaded--for example, if you are using the $_GET string for the $file & $path vars, you could have some problems because someone would be able to type in the path and name of any of your php files on the server and it would download them instead of parsing them.


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
  •