title: How to download file from database/folder using php
body: <p>File uploaded will be store in database and folder (folder name: uploads).Now I want to know how to create download file from database/folder. I have two file butangDonload.php and download.php. When user click word "donload" the pop up box will appear and save the file.</p>
  
  <p><strong>butangDonload.php</strong></p>
  
  <pre><code>&lt;?php
  
      $file = "Bang.png"; //Let say If I put the file name Bang.png
      echo "&lt;a href='download.php?nama=".$file."'&gt;donload&lt;/a&gt; ";
  
  ?&gt;
  </code></pre>
  
  <p><strong>download.php</strong></p>
  
  <pre><code>&lt;?php
      $name= $_GET['nama'];
      download($name);
  
      function download($name) {
          $file = $nama_fail;
  
          if (file_exists($file)) {
              header('Content-Description: File Transfer');
              header('Content-Type: application/octet-stream');
              header('Content-Disposition: attachment; filename='.basename($file));
              header('Content-Transfer-Encoding: binary');
              header('Expires: 0');
              header('Cache-Control: must-revalidate');
              header('Pragma: public');
              header('Content-Length: ' . filesize($file));
              ob_clean();
              flush();
              readfile($file);
              exit;
          }
      }
  ?&gt;
  </code></pre>