PHP implementation file forced download code

WBOY
Release: 2016-07-25 08:54:53
Original
888 people have browsed it
  1. /**
  2. * php force download file
  3. * edit: bbs.it-home.org
  4. */
  5. $file_dir = "./";
  6. $name = "test.txt";
  7. $file = fopen($file_dir.$name," r");
  8. Header("Content-type: application/octet-stream");
  9. Header("Accept-Ranges: bytes");
  10. Header("Accept-Length: ".filesize($file_dir . $name) );
  11. Header("Content-Disposition: attachment; filename=".$name);
  12. echo fread($file, filesize($file_dir.$name));
  13. fclose($file);
  14. ?>
Copy the code

The code is very simple. It mainly focuses on learning the principles and implementation methods of forced downloading of files in PHP. You can improve on this basis.



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