1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
   | $filename = basename($sourceFile);  $outFile_extension = strtolower(substr(strrchr($outFile, "."), 1)); 
  switch ($outFile_extension) {     case "exe" :         $ctype = "application/octet-stream";         break;     case "zip" :         $ctype = "application/zip";         break;     case "mp3" :         $ctype = "audio/mpeg";         break;     case "mpg" :         $ctype = "video/mpeg";         break;     case "avi" :         $ctype = "video/x-msvideo";         break;     default :         $ctype = "application/force-download"; }
  header("Cache-Control:"); header("Cache-Control: public");
  header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=" . $outFile); header("Accept-Ranges: bytes"); $size = filesize($sourceFile);
  if (isset ($_SERVER['HTTP_RANGE'])) {     
 
 
 
 
 
 
 
 
           list ($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);          str_replace($range, "-", $range);      $size2 = $size -1;      $new_length = $size2 - $range;      header("HTTP/1.1 206 Partial Content");     header("Content-Length: $new_length");      header("Content-Range: bytes $range$size2/$size");  } else {          $size2 = $size -1;     header("Content-Range: bytes 0-$size2/$size");      header("Content-Length: " . $size);  }
  $fp = fopen("$sourceFile", "rb");
  fseek($fp, $range);
  while (!feof($fp)) {          set_time_limit(0);     print (fread($fp, 1024 * 8));      flush();      ob_flush(); } fclose($fp); exit ();
   |