Advertisement
michaelyuen

Untitled

Jul 5th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',1); // enable php error display for easy trouble shooting
  3. error_reporting(E_ALL); // set error display to all
  4.  
  5.  
  6. function download($url) {
  7.     $file_headers = @get_headers($url);
  8.     // if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
  9.         // $router = new router;
  10.         // $router->show_error("URL DOES NOT EXIST");
  11.     // }    else    {
  12.  
  13.         switch(strtolower(substr(strrchr($url, '.'), 1))) {
  14.             case 'pdf':
  15.             $mime = 'application/pdf';
  16.             break;
  17.             case 'zip':
  18.             $mime = 'application/zip';
  19.             break;
  20.             case 'jpeg':
  21.             $mime = 'image/jpeg';
  22.             break;
  23.             case 'jpg':
  24.             $mime = 'image/jpg';
  25.             break;
  26.             default:
  27.             $mime = 'application/force-download';
  28.         }
  29.         set_time_limit(0);
  30.         header('Pragma: public'); // required
  31.         header('Expires: 0'); // no cache
  32.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  33.         header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($url)).' GMT');
  34.         header('Cache-Control: private',false);
  35.         header('Content-Type: '.$mime);
  36.         header('Content-Disposition: attachment; filename="'.basename($url).'"');
  37.         header('Content-Transfer-Encoding: binary');
  38.         header('Content-Length: '.filesize($url)); // provide file size
  39.         header('Connection: close');
  40.         readfile($url); // push it out
  41.         exit();
  42.     // }
  43. }
  44.  
  45.  
  46. $url = 'vm.jpg';
  47. download($url);
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement