title: Create a download button using html and php
body: <p>I want to create a download button using HTML and PHP. Below is my HTML code -</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
     &lt;head&gt;
         &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
     &lt;/head&gt;
     &lt;body&gt;
         &lt;form action="download.php" method="post"&gt;
             &lt;input type="submit" name="submit" value="Download File" /&gt;
         &lt;/form&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now I have created another file, called "download.php" and kept it in the same directory as my HTML file. Code of the PHP file is given below -</p>
  
  <pre><code>&lt;?php
    header('Content-Type: application/download');
    header('Content-Disposition: attachment; filename="Sample.mp3"');
    header("Content-Length: " . filesize("Sample.mp3"));
    $fp = fopen("Sample.mp3", "r");
    fpassthru($fp);
    fclose($fp);
  ?&gt;
  </code></pre>
  
  <p>Sample.mp3 is kept in same folder as HTML file. I got these codes from internet.</p>
  
  <p>Now my problem is, when I click on download button, content of the PHP file get opened rather than downloading the file.</p>
  
  <p>Can anyone please help me to fix this issue.</p>