PHP reads the file and provides download after changing the file name

WBOY
Release: 2016-07-25 09:02:34
Original
955 people have browsed it
  1. $filename = dirname(__FILE__) . '/oldfilename.exe';
  2. $out_filename = 'newfilename.exe';
  3. if()) {
  4. echo 'Not Found' . $filename;
  5. exit;
  6. } else {
  7. // We'll be outputting a file
  8. @header('Accept-Ranges: bytes');
  9. @header('Accept-Length: ' . filesize($filename));
  10. // It will be called
  11. @header('Content-Transfer-Encoding: binary');
  12. @header('Content-type: application/octet-stream');
  13. @header('Content-Disposition: attachment; filename=' . $out_filename);
  14. @header('Content-Type: application/octet-stream; name=' . $out_filename);
  15. // The source is in filename
  16. $file = @fopen($filename, "r");
  17. echo @fread($file, @filesize($filename));
  18. @fclose($file);
  19. exit;
  20. }
复制代码


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