title: CodeIgniter - error trying to view uploaded pdf files
body: <p>I'm having difficulty trying to view a pdf file outside of the webroot folder. </p>
  
  <p>This is the view file - I'm grabbing the file id from the URL and then querying the db to get all the file info stored from the upload.</p>
  
  <pre><code>     $fid = $_GET['fid'];
  $query = $this-&gt;db-&gt;query("SELECT * FROM files WHERE FID = $fid");
      $fileinfo = $query-&gt;result();
      foreach ($fileinfo as $row)
      {
  
  
      $fname = $row-&gt;file_name;
      $ftype =  $row-&gt;file_type;
      $fpath =  $row-&gt;file_path;
      $full_path = $row-&gt;full_path;
      $raw_name = $row-&gt;raw_name;
      $client_name = $row-&gt;client_name;
      $file_ext = $row-&gt;file_ext;
      $file_size =  $row-&gt;file_size;
      $is_image = $row-&gt;is_image;
      $width =  $row-&gt;image_width;
      $height = $row-&gt;image_height;
      $img_type =  $row-&gt;image_type;
      $img_size =  $row-&gt;image_size_str;
      $orig_name = $row-&gt;orig_name;
      $created =  $row-&gt;created;
  
      }
  </code></pre>
  
  <p>Then I'm taking that info and passing it to the File_viewer_model using the following:</p>
  
  <pre><code>    $this-&gt;load-&gt;model('File_viewer_model');
  
      $this-&gt;File_viewer_model-&gt;getFileInfo($fname,$ftype);
  </code></pre>
  
  <p>The function in the model that receives the data is as follows:</p>
  
  <pre><code>function getFileInfo($fname,$ftype){
  
  
     $path = '/home/sitename/uploads/' . $fname;
  
  
  header('Content-Type: ' . $ftype);
  header('Content-Length: ' . filesize($path));
  
  readfile($path);
  
          }
  </code></pre>
  
  <p>The problem is when I click on the link to open a new tab and try to display the file, I get the following error:</p>
  
  <blockquote>
    <p>File does not begin with '%PDF-'.</p>
  </blockquote>
  
  <p>The file is in a 777 permissions directory called uploads right outside of the webroot - I've been all over the web and there seems to be several methods to display a pdf file, none of which seem to work for me. Any help would be appreciated. Thanks!</p>