Home > Backend Development > PHP Tutorial > How to force image download in php by modifying header, _PHP tutorial

How to force image download in php by modifying header, _PHP tutorial

WBOY
Release: 2016-07-13 10:01:06
Original
843 people have browsed it

How to force image download in PHP by modifying the header,

This article describes the method of forcing image download in PHP by modifying the header. Share it with everyone for your reference. The specific implementation method is as follows:

function downloadFile($file){
 $file_name = $file;
 $mime = 'application/force-download';
 header('Pragma: public'); // required
 header('Expires: 0'); // no cache
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Cache-Control: private',false);
 header('Content-Type: '.$mime);
 header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
 header('Content-Transfer-Encoding: binary');
 header('Connection: close');
 readfile($file_name); // push it out
 exit();
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/972638.htmlTechArticleHow to force image download in PHP by modifying the header. This article describes the method of forcing image download in PHP by modifying the header. Share it with everyone for your reference. The specific implementation method is as follows:...
Related labels:
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