A simple example of using PHP to implement file download function

WBOY
Release: 2016-07-25 08:58:48
Original
940 people have browsed it

2, file get.php, the content is as follows:

  1. /**

  2. * php implements file download
  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 Chinese manual.doc','GB2312','UTF-8')); // For IE
  13. }else{
  14. header("Content-Disposition: attachment; filename= ".mb_convert_encoding('nginx Chinese manual.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. ?>

Copy Code


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!