title: Upload, View PDF in PHP
body: <p>So i was working on a upload, view file for my site but it seems only images and txt files are ready to view, PDF and word documents don't even show. Can someone tell how do i change this so that i can view pdf and word docs in browser?</p>
  
  <p>Here is the upload.php:</p>
  
  <pre><code>&lt;?php
  include_once 'dbconfig.php';
  if(isset($_POST['btn-upload']))
  {    
  
      $file = rand(1000,100000)."-".$_FILES['file']['name'];
      $file_loc = $_FILES['file']['tmp_name'];
      $file_size = $_FILES['file']['size'];
      $file_type = $_FILES['file']['type'];
      $folder="uploads/";
  
      // new file size in KB
      $new_size = $file_size/1024;  
      // new file size in KB
  
      // make file name in lower case
      $new_file_name = strtolower($file);
      // make file name in lower case
  
      $final_file=str_replace(' ','-',$new_file_name);
  
      if(move_uploaded_file($file_loc,$folder.$final_file))
      {
          $sql="INSERT INTO tbl_files(file,type,size) VALUES('$final_file','$file_type','$new_size')";
          mysql_query($sql);
          ?&gt;
          &lt;script&gt;
          alert('successfully uploaded');
          window.location.href='index.php?success';
          &lt;/script&gt;
          &lt;?php
      }
      else
      {
          ?&gt;
          &lt;script&gt;
          alert('error while uploading file');
          window.location.href='index.php?fail';
          &lt;/script&gt;
          &lt;?php
      }
  }
  ?&gt;
  </code></pre>
  
  <p>And here is the view.php (Updated and working):</p>
  
  <pre><code> &lt;?php
    $file = 'uploads/.pdf';
    $filename = 'yolo.pdf';
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' . $filename . '"');
    header('Content-Transfer-Encoding: binary');
    header('Accept-Ranges: bytes');
    @readfile($file);
  ?&gt;
  </code></pre>
  
  <p>I only need this to be able to view any PDF without having to have a specific name in the code : <code>$filename = 'yolo.pdf';</code></p>
  
  <p>I have a list of PDF files for the users to see. Is it possible, when clicking the view button, to read the id of the pdf file in the database and to store it in a variable which will be placed in the code? This way php will view the specific file whithout having to change code for every file...</p>
  
  <p>I know this may sound a little confusing so any question just say.</p>