header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$filename\";" ); header("Content-Transfer-Encoding: binary"); PHP: I am using this header for creating csv file. It works fine in FF & Chrome. Problem is with IE. In download alert i get file type 'HTML Document'. It was working fine 2 days ago. Now i don't know what get changed or went wrong and all of the sudden file type is wrong and instead of getting csv file download i am getting all csv values in browser window. Please suggest a fix for it.
Before the session_start(); if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { session_cache_limiter("public"); } session_start(); Code (markup):
I'm wondering why you're dicking around setting so many HTTP controls in the first place, but then I never fell into the cache-control micromanagement LIES some developers seem to be packing raging chubbies for... ... and ugur_ben is correct -- in fact that's the ONLY heading I'd be setting if I was generating a CSV file from PHP. MIME-TYPE so the UA has some clue what to do with it. I'd delete ALL those other header statements, at least until you get it working properly. In fact, I'd say IE is the only browser handling it PROPERLY -- since without setting the mime-type the result should be treated as text/html and displayed, not downloaded.