解析PHP實現(xiàn)下載文件的兩種方法_PHP教程
推薦:PHP系統(tǒng)命令函數(shù)使用分析本篇文章是對PHP中系統(tǒng)命令函數(shù)的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下: function execute($cmd) { $res = ''; if ($cmd) { if(function_exists('system')) { @ob_start(); @system($cmd); $res = @ob_get_contents(); @ob_end_clean(); } els
本篇文章是對使用PHP實現(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();
分享:WordPress禁止輸出錯誤信息設(shè)置方法用網(wǎng)站安全檢測掃瞄博客,發(fā)現(xiàn)了一個漏洞,實際上就是直接訪問主題路徑的話,get_header()函數(shù)未生效(Call to undefined function get_header() ),而我的WordPress會輸出完整的錯誤信息,將敏感名稱的目錄結(jié)構(gòu)暴露了,雖然對正常訪問沒有影響,可是會給某些人可乘之
- 相關(guān)鏈接:
- 教程說明:
PHP教程-解析PHP實現(xiàn)下載文件的兩種方法
。