解析PHP實現(xiàn)下載文件的兩種方法
更新時間:2013年07月05日 08:49:35 作者:
本篇文章是對使用PHP實現(xiàn)下載文件的兩種方法進行了詳細的分析介紹,需要的朋友參考下
方法一:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filepath));
header('Content-Transfer-Encoding: binary');
header('Expires: 0′);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
readfile($file_path);
方法二:
$fileinfo = pathinfo($filename);
header('Content-type: application/x-'.$fileinfo['extension']);
header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
header('Content-Length: '.filesize($filename));
readfile($thefile);
exit();
復制代碼 代碼如下:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filepath));
header('Content-Transfer-Encoding: binary');
header('Expires: 0′);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
readfile($file_path);
方法二:
復制代碼 代碼如下:
$fileinfo = pathinfo($filename);
header('Content-type: application/x-'.$fileinfo['extension']);
header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
header('Content-Length: '.filesize($filename));
readfile($thefile);
exit();
您可能感興趣的文章:
- 分享一個超好用的php header下載函數(shù)
- 使用PHP強制下載PDF文件示例
- PHP 下載文件時自動添加bom頭的方法實例
- PHP IE中下載附件問題解決方法
- php下載excel無法打開的解決方法
- php讀取csv實現(xiàn)csv文件下載功能
- php實現(xiàn)文件下載(支持中文文名)
- php使瀏覽器直接下載pdf文件的方法
- php 強制下載文件實現(xiàn)代碼
- 使用PHP下載CSS文件中的圖片的代碼
- php 下載保存文件保存到本地的兩種實現(xiàn)方法
- php對csv文件的讀取,寫入,輸出下載操作詳解
- 解析獲取優(yōu)酷視頻真實下載地址的PHP源代碼
- 解析php下載遠程圖片函數(shù) 可偽造來路
- 解析php多線程下載遠程多個文件
- 解析如何在PHP下載文件名中解決亂碼的問題
- 解決PHP超大文件下載,斷點續(xù)傳下載的方法詳解
- php實現(xiàn)下載限制速度示例分享
相關(guān)文章
PHP基于遞歸實現(xiàn)的約瑟夫環(huán)算法示例
這篇文章主要介紹了PHP基于遞歸實現(xiàn)的約瑟夫環(huán)算法,結(jié)合實例形式較為詳細的分析了約瑟夫環(huán)問題與php使用遞歸算法的解決方法,需要的朋友可以參考下2017-08-08PHP中使用SimpleXML檢查XML文件結(jié)構(gòu)實例
這篇文章主要介紹了PHP中使用SimpleXML檢查XML文件結(jié)構(gòu)實例,本文講解使用SimpleXML來檢查一個XML文件是否符合規(guī)范的方法,需要的朋友可以參考下2015-01-01