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:00:44
Original
823 people have browsed it

How to force image download in php by modifying the header

This article mainly introduces the method of forcing image download in php by modifying the header, and analyzes the techniques of forcing image download in php with examples. It has certain reference value, friends in need can refer to it

The example in this article describes how PHP forces image downloading by modifying the header. Share it with everyone for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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();

}

1 2

3

4 5

67 8 9 10 11 12
13
14
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(); }
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/973113.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973113.htmlTechArticleHow to force image download in PHP by modifying the header. This article mainly introduces the method of forcing image download in PHP by modifying the header. , the example analyzes the technique of php forcing image downloading, with certain...
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