title: PHP not loading full image on first load, but loading full image on subsequent loads till refresh
body: <p>I am working on a gallery page that uses PHP to load images outside web root, on my initial webpage I have thumbnails sitting within an anchor tag that that looks like this for calling the medium sized image onclick</p>
  
  <pre><code>    href="/view_file.php?file=115&amp;medium=1&amp;v=239"
  </code></pre>
  
  <p>and this calls this bit of code from the view_file page</p>
  
  <pre><code>        case "jpg":
              header('Content-length: ' . $fsize);
              header('Cache-control: private');
              header('Content-type: ' . $fmime . '; name="' . $nameOrig . '.' . $fext . '"');
              header('Content-Disposition: inline; filename="' . $nameOrig . '.' . $fext . '"');
              $modified=filemtime($fullPath);
              header('Last-Modified: '. date('D, j M Y G:i:s T',$modified));
              ob_clean();
              flush();
              @readfile($fullPath);
              exit;
  </code></pre>
  
  <p>This bit of code is also used to display the thumbnails on the original page. However when loading the medium sized images, it only loads about the first 5% or so of the image before stopping. If i go back and click on the same image again, i am presented with the full sized medium image. If i refresh the thumbnail page i once again run into the same issue. 
  Full view file page in the pastebin linked below
  <a href="http://pastebin.com/vhd46Pdw" rel="nofollow">http://pastebin.com/vhd46Pdw</a></p>
  
  <p>EDIT
  after tinkering around a bit, i found that the $fsize variable is being set incorrectly on the first load, however upon page refresh it is loaded with the correct variable</p>