>  기사  >  php教程  >  简单的下载文件函数

简单的下载文件函数

WBOY
WBOY원래의
2016-06-07 11:44:461117검색

发送文件给浏览器,提供下载,支持个大浏览器及中文文件名。
//下载文件<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으로 문의하세요.