title: php image file download by code
body: <p>This concerns downloading files with PHP</p>
  
  <p>My php version is 5.3.5 and my apache is 2.2.17</p>
  
  <p>I am trying to dowload files (pdf,jpg,tiff) that I have uploaded in my server, and they download with the same size and type but I can not see them. I am guessing they are not copied right. But when I open the original uploaded ones they work just fine.
  I have seen almost all the questions that appeared as suggested and none of them answered the question, te only similar one is <a href="https://stackoverflow.com/questions/1543798/image-file-download-problem">this</a>, but still doesnt answer my question.</p>
  
  <p>to download I am using this code</p>
  
  <pre><code>       header("Content-type: application/force-download"); 
         header('Content-Disposition: inline; filename="' . $dir . '"'); 
         header("Content-Transfer-Encoding: Binary"); 
         header("Cache-Control: no-store, no-cache, must-revalidate");  
         header("Cache-Control: post-check=0, pre-check=0", false);  
         header("Pragma: no-cache"); 
         header("Content-length: ".filesize($dir)); 
         header('Content-Type: application/octet-stream'); 
         header('Content-Disposition: attachment; filename="' . $file . '"'); 
         readfile("$dir"); 
  </code></pre>
  
  <p>where <code>$dir="62756d616769636e63/646973736572746174/ehddggh/1.JPG"</code>
  and <code>$file="1.JPG"</code></p>
  
  <p>can anyone give me a hint on what I am doing wrong, or give me a better solution to download files?</p>