Home > Backend Development > PHP Tutorial > PHP code to force image download by modifying header

PHP code to force image download by modifying header

WBOY
Release: 2016-07-25 08:45:46
Original
1027 people have browsed it
  1. unction downloadFile($file){
  2. $file_name = $file;
  3. $mime = 'application/force-download';
  4. header('Pragma: public'); // required
  5. header('Expires: 0'); // no cache
  6. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  7. header('Cache-Control: private',false);
  8. header('Content-Type: '.$mime);
  9. header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
  10. header('Content-Transfer-Encoding: binary');
  11. header('Connection: close');
  12. readfile($file_name); // push it out
  13. exit();
  14. }
复制代码

php, header


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