-
-
- $filename = "./".$_REQUEST['name']; //Specific path, as long as $filename is the full path of the file you want to download
- if (!is_file($ filename)) {//Check whether the file exists.
- die('The downloaded file seems to have eloped with someone!');
- }
- $filepath = str_replace('\', '/', realpath($filename)) ;
- $filesize = filesize($filepath);
- $filename = substr(strrchr('/'.$filepath, '/'), 1);
- $extension = strtolower(substr(strrchr($filepath, '.' ), 1));
- // use this unless you want to find the mime type based on extension, file suffix format, not interpreted.
- $mime = array('application/octet-stream');
- header('Content -Type: '.$mime);
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header('Content-Transfer-Encoding: binary');
- header(' Content-Length: '.sprintf('%d', $filesize));
- header('Expires: 0');
- // check for IE only headers, cheating IE detection, you know.
- if (isset ($_SERVER['HTTP_USER_AGENT']) &&((strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)))
- {
- header('Cache-Control: must-revalidate, post-check =0, pre-check=0');
- header('Pragma: public');
- } // bbs.it-home.org
- else
- {
- header('Pragma: no-cache');
- }
- $handle = fopen($filepath, 'rb');
- fpassthru($handle);
- fclose($handle);
Copy code
Instructions:
The above code was found by Brother Feng from a foreign website and can be used for personal testing.
The script editor collected and organized it, thank the original author Feng Ge for producing it~~~
|