相容ie6瀏覽器的php下載檔案代碼分享,_PHP教程

來源:互聯網
上載者:User

相容ie6瀏覽器的php下載檔案代碼分享,


PS:這段代碼在win系統下跑沒有問題,楓哥親測可用.如果用的是linux或是其他系統,要要諸位自行測試下啦.

$filename = "./".$_REQUEST['name']; //這裡是楓哥具體路徑,只要$filename是所要下載檔案的完整路徑就可以.if (!is_file($filename)) {//檢測檔案是否存在. die('下載的檔案好像跟TM誰私奔啦!');}$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檢測,你懂的.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);

這個代碼是楓哥從國外的一個網站上找到的,親測可用.度娘出來的結果,你懂的.因此在部落格上共用出來,希望對大家有用.國外的站,地址忘了,沒有辦法放出,理解下.最後,嚴肅的聲明下:這個代碼不是我寫的,是轉載的.




http://www.bkjia.com/PHPjc/840643.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/840643.htmlTechArticle相容ie6瀏覽器的php下載檔案代碼分享, PS:這段代碼在win系統下跑沒有問題,楓哥親測可用.如果用的是linux或是其他系統,要要諸位自行測試下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.