title: Download PDF file from database using PHP
body: <p>I have to download most recent uploaded PDF file from MySQL database using PHP. The file can view but while saving it to local folder, instead of saving it as .pdf , it saves .php. and that .php file contains encoded data.</p>
  
  <p>Can anyone suggest how I download/save .pdf file? Code is:</p>
  
  <pre><code>&lt;?php 
  include 'connection.php';
  
    $sql=mysqli_query($connection,"Select name,content from ekalp where id = (select max(id) from ekalp)"); 
  $result=mysqli_fetch_assoc($sql);
  //$resu=$result['name']; 
  $result=$result['content'];
  echo $result."&lt;br&gt;";
  $filename = $result.'pdf';
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' . $filename . '"');
    header('Content-Transfer-Encoding: binary');
    header('Accept-Ranges: bytes');
    ob_clean();
    ob_flush ();
    @readfile($filename);
   mysqli_close($connection);
  
  ?&gt;
  </code></pre>