萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 解析PHP實現下載文件的兩種方法

解析PHP實現下載文件的兩種方法

本篇文章是對使用PHP實現下載文件的兩種方法進行了詳細的分析介紹,需要的朋友參考下  

方法一:

復制代碼 代碼如下:
 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();

copyright © 萬盛學電腦網 all rights reserved