I've tried many PHP scripts to build a force download page but failed every time. I have a download link on each page and clicking which I want user to be redirected to another page and the download begins.
I'm passing the full absolute path URL in the parameter as <a href="download.php?filename=http://www.abc.com/maps/map.pdf" target="_blank">Download PDF</a>
the code of my download.php file is
<?php
$file = $_GET["filename"];
$file_name = basename($file);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: " . filesize($file)); //added this line
readfile($file);
?>
If your download doesn't start
<a href="<?php echo $_GET["filename"]; ?>" target="_blank">click here</a>
Errors:
Download.php is getting the parameter filename value correctly but says
Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/11973872/html/filerepairtool/down/download.php:9) in /home/content/72/11973872/html/filerepairtool/down/download.php on line 20
Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/11973872/html/filerepairtool/down/download.php:9) in /home/content/72/11973872/html/filerepairtool/down/download.php on line 21
I want to build a page like the download page in most of the software download sites where clicking the download link takes us to another URL which says something like "Your download should begin in 10 seconds (With second countdown) OR Click here to download if it doesn't start"
Please share the solution