欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

兼容ie6瀏覽器的php下載文件代碼分享

 更新時(shí)間:2014年07月14日 11:21:34   投稿:junjie  
這篇文章主要介紹了兼容ie6瀏覽器的php下載文件代碼分享,解決了ie6下無(wú)法下載文件的bug,需要的朋友可以參考下

PS:這段代碼在win系統(tǒng)下跑沒(méi)有問(wèn)題,楓哥親測(cè)可用.如果用的是linux或是其他系統(tǒng),要要諸位自行測(cè)試下啦.

$filename = "./".$_REQUEST['name']; //這里是楓哥具體路徑,只要$filename是所要下載文件的完整路徑就可以.
if (!is_file($filename)) {//檢測(cè)文件是否存在.
 die('下載的文件好像跟TM誰(shuí)私奔啦!');
}
$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,文件后綴格式,不解釋.
$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,坑爹的IE檢測(cè),你懂的.
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);

這個(gè)代碼是楓哥從國(guó)外的一個(gè)站點(diǎn)上找到的,親測(cè)可用.度娘出來(lái)的結(jié)果,你懂的.因此在博客上共享出來(lái),希望對(duì)大家有用.國(guó)外的站,地址忘了,沒(méi)有辦法放出,理解下.最后,嚴(yán)肅的聲明下:這個(gè)代碼不是我寫(xiě)的,是轉(zhuǎn)載的.

相關(guān)文章

最新評(píng)論