欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php读取文件 更改文件名后提供下载

程序员文章站 2024-02-09 10:50:22
...
  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. }
复制代码