downloading issue in php .. return invalid file?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12542203/try-to-download-file-and-getting-invalid-file-in-response-in-core-php">try to download file and getting invalid file in response in core php</a>  </p>
</blockquote>



<pre><code>$filename=gallery/downloads/poster/large/h.jpg  
</code></pre>

<p>path to download file is correct but don't know why it give invalid file in return ...  </p>

<pre><code> $filename = $_GET["filename"]; 
 $buffer = file_get_contents($filename);

    /* Force download dialog... */
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header('Content-Type: image/jpeg');

    /* Don't allow caching... */
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

    /* Set data type, size and filename */
    header("Content-Type: application/octet-stream");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . strlen($buffer));
    header("Content-Disposition: attachment; filename=$filename");

    /* Send our file... */
   echo $buffer;
</code></pre>

<p>if u have a better way then please share .... thanks in advance .</p>
