A force-download script can give you more control over a file download than you would have providing a direct link that may be the good thing most of the time to read it online. But sometimes it can be very frustrating to click on a link to a document you want people to read, and then have to wait for it to download and finally open on your computer that may not have the right program to open it.
But what if you have a file you want people to download ? If it is an HTML file or a PDF file or an image file or a video file, you cannot just post link, as the web browsers open those automatically; instead you need to do some tricky thing using PHP.
PHP allows you to change the HTTP headers of files that you are writing, so that you can force a file to be downloaded that normally the browser would load in the same window. This is perfect for files like PDFs, document files, images, and video that you want your customers to download rather than read online. Continue reading “Force download a file using PHP”