How to Force Download File in PHP
Submitted by alpha_luna on Saturday, September 24, 2016 - 14:02.
If you are looking for how to Force Download File in PHP then you are at the right place. If you are going to download any file using PHP, you need a browser to force download the file without displaying it. We are going to show you how to download any file direct to the server in PHP. The example script that can be used for downloading the file in any types like image, text, document, zip file and pdf.
Check the Live Demo.
PHP Download Query
This query use to download a file in PHP. Copy and paste this query and save it as "download.php".
Create Simple Markup and Download Button
This simple HTML source code where you can use the button to force download the file in PHP. Kindly copy and paste to the BODY tag of your web page.
- <?php
- $filePath = 'file_to_download/'.$downloadable_name;
- // Define headers
- // Read the file
- exit;
- }else{
- echo 'The file does not exist.';
- }
- }
Output
That's it, kindly click the "Download Code" button below for the full source code. Enjoy coding.Add new comment
- 282 views