Home > php教程 > php手册 > 简单的下载文件函数

简单的下载文件函数

WBOY
Release: 2016-06-07 11:44:46
Original
1162 people have browsed it

发送文件给浏览器,提供下载,支持个大浏览器及中文文件名。
//下载文件<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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template