Advertisement
Guest User

PHP Fetch Script

a guest
May 16th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3.  // USE:  http://yourdomain/thisfile.php?file=/path/to/file.ext
  4.  // Most of this file was snagged off the web somewhere.
  5.  
  6.  // Don't timeout when downloading large files
  7.  @ignore_user_abort();
  8.  @set_time_limit(0);
  9.  
  10.  // Get list name
  11.  $file = $_GET['file'];
  12.  $fullfile = "E:/PATH/TO/FILES/".$file;          // REPLACE THIS PATH WITH THE ACTUAL PATH
  13.  
  14.  // Make sure list is set and file exists
  15.  echo $fullfile;
  16.  if((!$file) or (!file_exists($fullfile))) {
  17.  die("File was not set or did not exist");
  18.  }
  19.  
  20.  // Create the pointer to our file and open it as read-only binary data
  21.  $fp = fopen($fullfile,'rb');
  22.  
  23.  // Send headers telling browser to download our passed data
  24.  header("Content-Type: application/octet-stream");
  25.  header("Pragma: no-cache");
  26.  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  27.  header("Content-Length: " . filesize($fullfile));
  28.  header("Accept-Ranges: bytes");
  29.  header("Content-Disposition: attachment; filename=\"$file\"");
  30.  
  31.  // Here comes the data
  32. readfile($fullfile);
  33.  fclose ($fp);
  34.  exit();
  35.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement