php实现文件下载功能的简单例子

原创
2016-07-25 08:58:48 673浏览

2,文件get.php,内容如下:

  1. /**

  2. * php实现文件下载
  3. * edit bbs.it-home.org
  4. */
  5. if (!isset(GET["file"]) || !isset(GET["type"])) {
  6. print "no file selsect"; exit();
  7. }
  8. $file = GET["file"].".".GET["type"];

  9. if (@$fp = fopen($file,'r')){
  10. header ("Content-type: octet/stream");
  11. if (strstr(SERVER["HTTP_USER_AGENT"], "MSIE")){
  12. header("Content-Disposition: filename=".mb_convert_encoding('nginx中文手册.doc','GB2312','UTF-8')); // For IE
  13. }else{
  14. header("Content-Disposition: attachment; filename=".mb_convert_encoding('nginx中文手册.doc','GB2312','UTF-8')); // For Other browsers
  15. } while(!@feof($fp)){
  16. echo fread($fp,1024);
  17. }
  18. //@fpassthru($fp);
  19. exit();
  20. } else{
  21. print "sorry,file not exists!";
  22. }
  23. ?>
复制代码


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。