首頁  >  文章  >  php教程  >  简单的下载文件函数

简单的下载文件函数

WBOY
WBOY原創
2016-06-07 11:44:461118瀏覽

发送文件给浏览器,提供下载,支持个大浏览器及中文文件名。
//下载文件<br> function download_file($file){<br>     if(is_file($file)){<br>         $length = filesize($file);<br>         $type = mime_content_type($file);<br>         $showname =  ltrim(strrchr($file,'/'),'/');<br>         header("Content-Description: File Transfer");<br>         header('Content-type: ' . $type);<br>         header('Content-Length:' . $length);<br>          if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE<br>              header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');<br>          } else {<br>              header('Content-Disposition: attachment; filename="' . $showname . '"');<br>          }<br>          readfile($file);<br>          exit;<br>      } else {<br>          exit('文件已被删除!');<br>      }<br>  }

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn