How to use PHP to force File Download PHP allows you to change what you write, so that you can force a file to be downloaded, usually, the browser loads the HTTP header of the file in the same window. This is perfect for files, such as PDF files, document files, images, and videos. you want your customers to download them instead of reading them online. The specific method is as follows: 1. you want to download the file to your Web server. For example, huge_document1_2 is used to edit how to use PHP to force file download.
PHP allows you to change what you write, which forces an object to be downloaded. Normally, the browser loads the HTTP header of the object in the same window. This is perfect for files, such as PDF files, document files, images, and videos. you want your customers to download them instead of reading them online.
The specific method is as follows:
1. you want to download the file to your Web server. For example,
Huge_document.pdf
2. edit the new PHP file. I suggest you name it the file you downloaded with the same name, just for PHP extension. For example:
Huge_document.php
3. open the PHP module:
<? PHP
4. set the HTTP header in the next line:
Header ('content-disposition: attachment; filename=huge_documentate ');
5. set the MIME type of the file:
Header ('content-type: application/pdf ');
6. point to the file you want to download:
Readfile('huge_document ');
7. disable the PHP block and save the file:
> [/BLOCKQUOTE>
8. your php file should be like this:
Header ('content-disposition: attachment; filename=huge_documentate ');
Header ('content-type: application/pdf ');
Readfile('huge_document ');
?>
9. download link to your php file. For example:
Download huge files (PDF)
Address: http://www.software8.co/wzjs/PHPshili/942.html
Tip:
There should be no space or carriage return in this file. Empty lines will make PHP text/html by default and your files cannot be downloaded.