Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- function download($url) {
- $file_headers = @get_headers($url);
- // if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
- // $router = new router;
- // $router->show_error("URL DOES NOT EXIST");
- // } else {
- switch(strtolower(substr(strrchr($url, '.'), 1))) {
- case 'pdf':
- $mime = 'application/pdf';
- break;
- case 'zip':
- $mime = 'application/zip';
- break;
- case 'jpeg':
- $mime = 'image/jpeg';
- break;
- case 'jpg':
- $mime = 'image/jpg';
- break;
- default:
- $mime = 'application/force-download';
- }
- set_time_limit(0);
- header('Pragma: public'); // required
- header('Expires: 0'); // no cache
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($url)).' GMT');
- header('Cache-Control: private',false);
- header('Content-Type: '.$mime);
- header('Content-Disposition: attachment; filename="'.basename($url).'"');
- header('Content-Transfer-Encoding: binary');
- header('Content-Length: '.filesize($url)); // provide file size
- header('Connection: close');
- readfile($url); // push it out
- exit();
- // }
- }
- $url = 'vm.jpg';
- download($url);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement