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. 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_document1_2. edit the new PHP file-I suggest you name it the same as the name of the downloaded file, just for PHP extension. For example: huge_document.php3, open the PHP module: <? PHP4, in the next line, set the HTTP header: header ('content-disposition: attachment; filename=huge_document='); 5, and then set the MIME type of the file: header ('content-type: application/pdf '); 6. point to the file you want to download: readfile('huge_document.pdf'); 7. close the PHP block and save the file:> [/BLOCKQUOTE> 8. your php file should be like this: 9. download link to your php file. For example, download a huge file (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.