PHP实现简单的文件下载通用方法

WBOY
發布: 2016-07-25 08:45:16
原創
731 人瀏覽過
  1. function download_file($file){
  2. if(is_file($file)){
  3. $length = filesize($file);
  4. $type = mime_content_type($file);
  5. $showname = ltrim(strrchr($file,'/'),'/');
  6. header("Content-Description: File Transfer");
  7. header('Content-type: ' . $type);
  8. header('Content-Length:' . $length);
  9. if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
  10. header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');
  11. } else {
  12. header('Content-Disposition: attachment; filename="' . $showname . '"');
  13. }
  14. readfile($file);
  15. exit;
  16. } else {
  17. exit('文件已被删除!');
  18. }
  19. }
复制代码

PHP


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!