IE is not able to download csv file correctly

Discussion in 'Programming' started by greatlogix, Mar 11, 2013.

  1. #1
    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.
     
    greatlogix, Mar 11, 2013 IP
  2. ugur_ben

    ugur_ben Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Before the session_start();

    if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
        session_cache_limiter("public");
    }
    session_start();
    Code (markup):
     
    ugur_ben, Mar 11, 2013 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    I have already tried this. Not working :(
     
    greatlogix, Mar 11, 2013 IP
  4. ugur_ben

    ugur_ben Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Try to play with content type?
    header('Content-Type: text/csv');
    Code (markup):
     
    ugur_ben, Mar 11, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    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.
     
    deathshadow, Mar 11, 2013 IP
  6. markjayswal

    markjayswal Greenhorn

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    http://joseph.randomnetworks.com/2004/10/01/making-ie-accept-file-downloads/
     
    markjayswal, Mar 13, 2013 IP
  7. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #7
    At last my manager updated IE and all problems gone :DThanks all for your response.
     
    greatlogix, Mar 13, 2013 IP