Code Sharing of php Download File Compatible with ie6 Browser
- 2021-07-09 07:29:56
- OfStack
PS: This code runs under the win system no problem, Feng Ge pro-test available. If you use linux or other systems, you need to test it yourself.
$filename = "./".$_REQUEST['name']; // Here is the specific path of Feng Ge , As long as $filename Is the full path of the file to be downloaded .
if (!is_file($filename)) {// Detect the existence of a file .
die(' The downloaded file seems to be similar to TM Who eloped !');
}
$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 , Do not explain .
$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, Patty 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');
}
else
{
header('Pragma: no-cache');
}
$handle = fopen($filepath, 'rb');
fpassthru($handle);
fclose($handle);
This code is maple elder brother from a foreign site found, pro-test available. Du Niang out of the results, you understand. So in the blog shared out, I hope to be useful to everyone. Foreign station, address forgot, no way to release, understand. Finally, serious statement: This code is not written by me, is reproduced.