title: Link to a PDF file stored in MySQL database using PHP
body: <p>I have a MySQL database that shows various user inputs from a web form. On a separate page, the database is shown to my employees. I want to have a link in the database that shows the uploaded PDF file when it is clicked.</p>
  
  <p>I have researched this issue for 2 weeks now, and none of the solutions have worked for me. I have searched Stack Overflow, as well as multiple other sites that came up in a Google search related to my problem. I know that this should be a simple fix, but I believe I am overthinking the issue.</p>
  
  <p>To upload the file path into my database, I used:</p>
  
  <pre><code>&lt;?php
      $database = "db";
  
      $mysqli = new mysqli("localhost", "root", "", $database);
      mysqli-&gt;select_db($database);
  
      $upload = rand(1000,100000)."-".$_FILES['upload']['name'];
      $uploadLocation = $_FILES['upload']['tmp_name'];
  
      $folder = "uploads/";
  
      move_uploaded_file($uploadLocation, $folder.$upload);
  
      $query = "INSERT INTO table (upload) VALUES ('{$uploadLocation}');
  
      $mysqli-&gt;query($query);
      $mysqli-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>To view the database on a separate page, I used:</p>
  
  <pre><code>&lt;?php
      $result = mysqli_query($mysqli, "SELECT upload FROM table");
  
      if ($result) {
          while($row = mysqli_fetch_array($result)) {
              echo '&lt;td&gt;&lt;a href="upload.php"&gt;' . $row['upload'] . '&lt;/a&gt;&lt;/td&gt;';
          }
      }
  
      mysqli_free_result($result);
  ?&gt;
  </code></pre>
  
  <p>When the link to the PDF file is clicked, I used:</p>
  
  <pre><code>&lt;?php
      $file = ' . $folder.$upload . ';
      $filename = ' . $folder.$upload . ';
      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 believe that the problem lies within my page where the PDF is clicked. The other 2 pages work fine, and everything shows up in the database as it should. However, when you click on the PDF file link in the database, an Acrobat Reader page pops up in the browser and says that the file cannot be read. Could someone help point me in the right direction as to what I'm doing wrong?</p>