Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with PHP readfile() dumping binary data to the browser
    primarykey
    data
    text
    <p>I trying to force a download by the browser here is my code:</p> <pre><code>header("Content-Type: application/force-download"); header('Content-type: audio/mp3'); header('Content-Description: File Download'); header('Content-Disposition: attachment; filename=' . $file_name); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-length: ' . filesize($file_path); ob_clean(); flush(); readfile($file_path); </code></pre> <p>This works perfectly on my local machine, but when I upload it to my live server, the binary file is dumped to the browser and those gibberish characters fill up the browser window. What could be the problem? I am on a shared server so I don't know if my apache configuration needs to be changed or something.</p> <p>I took @sanmi advice and used Firebug to see the response header and here is what I got:</p> <pre><code>Here is what I got sanmai: Server nginx/0.7.67 Date Tue, 06 Sep 2011 15:02:03 GMT Content-Type text/html; charset=UTF-8 Transfer-Encoding chunked Connection keep-alive Expires Thu, 19 Nov 1981 08:52:00 GMT Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma no-cache Vary Accept-Encoding,User-Agent Content-Encoding gzip </code></pre> <p>I can see that the content-type entry has changed to text/html, and that the server is actually a nginx one. So is this a nginx issue or are my header entries wrong?</p> <p>Thanks, Tsega</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload