title: PHP Force Download Error
body: <p>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.</p>
  
  <p>I'm passing the full absolute path URL in the parameter as <code>&lt;a href="download.php?filename=http://www.abc.com/maps/map.pdf" target="_blank"&gt;Download PDF&lt;/a&gt;</code></p>
  
  <p>the code of my download.php file is </p>
  
  <pre><code>&lt;?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);
  ?&gt;
  </code></pre>
  
  <p>If your download doesn't start </p>
  
  <pre><code>&lt;a href="&lt;?php echo $_GET["filename"]; ?&gt;" target="_blank"&gt;click here&lt;/a&gt;
  </code></pre>
  
  <p>Errors:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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"</p>
  
  <p>Please share the solution</p>