解析PHP實(shí)現(xiàn)下載文件的兩種方法
更新時(shí)間:2013年07月05日 08:49:35 作者:
本篇文章是對使用PHP實(shí)現(xiàn)下載文件的兩種方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
方法一:
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();
復(fù)制代碼 代碼如下:
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);
方法二:
復(fù)制代碼 代碼如下:
$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();
您可能感興趣的文章:
- 分享一個(gè)超好用的php header下載函數(shù)
- 使用PHP強(qiáng)制下載PDF文件示例
- PHP 下載文件時(shí)自動添加bom頭的方法實(shí)例
- PHP IE中下載附件問題解決方法
- php下載excel無法打開的解決方法
- php讀取csv實(shí)現(xiàn)csv文件下載功能
- php實(shí)現(xiàn)文件下載(支持中文文名)
- php使瀏覽器直接下載pdf文件的方法
- php 強(qiáng)制下載文件實(shí)現(xiàn)代碼
- 使用PHP下載CSS文件中的圖片的代碼
- php 下載保存文件保存到本地的兩種實(shí)現(xiàn)方法
- php對csv文件的讀取,寫入,輸出下載操作詳解
- 解析獲取優(yōu)酷視頻真實(shí)下載地址的PHP源代碼
- 解析php下載遠(yuǎn)程圖片函數(shù) 可偽造來路
- 解析php多線程下載遠(yuǎn)程多個(gè)文件
- 解析如何在PHP下載文件名中解決亂碼的問題
- 解決PHP超大文件下載,斷點(diǎn)續(xù)傳下載的方法詳解
- php實(shí)現(xiàn)下載限制速度示例分享
相關(guān)文章
PHP基于遞歸實(shí)現(xiàn)的約瑟夫環(huán)算法示例
這篇文章主要介紹了PHP基于遞歸實(shí)現(xiàn)的約瑟夫環(huán)算法,結(jié)合實(shí)例形式較為詳細(xì)的分析了約瑟夫環(huán)問題與php使用遞歸算法的解決方法,需要的朋友可以參考下2017-08-08PHP中使用SimpleXML檢查XML文件結(jié)構(gòu)實(shí)例
這篇文章主要介紹了PHP中使用SimpleXML檢查XML文件結(jié)構(gòu)實(shí)例,本文講解使用SimpleXML來檢查一個(gè)XML文件是否符合規(guī)范的方法,需要的朋友可以參考下2015-01-01