shayansulehri

download

Aug 28th, 2014
265
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. if(isset($_GET['FileName']))
  3. {
  4. $fullPath = $MainDirectory.$_GET['FileName'];
  5.  if ($fd = fopen ($fullPath, "r")) {
  6.     $fsize = filesize($fullPath);
  7.     $path_parts = pathinfo($fullPath);
  8.    
  9.     if(isset($path_parts["extension"]))
  10.     {
  11.     $ext = strtolower($path_parts["extension"]);
  12.     }
  13.     else
  14.     {
  15.     $ext="";
  16.     }
  17.    
  18.     switch ($ext) {
  19.         case "pdf":
  20.         $mime_type ="application/pdf";
  21.          break;
  22.  
  23.          case "txt":
  24.         $mime_type ="force-download";
  25.          break;
  26.        
  27.        default:
  28.         $mime_type="application/force-download";
  29.        break;
  30.     }
  31.      header("Content-type: ".$mime_type);
  32.         header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
  33.         header("Content-Transfer-Encoding: binary");
  34.         header("Accept-Ranges: bytes");
  35.  
  36.     header("Content-length: $fsize");
  37.     header("Cache-control: private"); //use this to open files directly
  38.     while(!feof($fd)) {
  39.         $buffer = fread($fd, 2048);
  40.         echo $buffer;
  41.     }
  42. }
  43. fclose ($fd);
  44.  
  45.  }
  46. ?>
Add Comment
Please, Sign In to add comment