Problem in downloading a excel file in IE6 & IE7 – PHP

  php

Q(Question):

Hi to all,
i am written a code for downloading the excel file with the records from the mysql..all r working fine but the problem is…it is not downloading in IE6 and IE7…i dont no where is the problem is..and not showing any error msg also please help me this the code is


<?php
$today = date("d-m-Y");
session_cache_limiter('none');
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Description: File Transfer');
header("Content-type: application/vnd.ms-excel;charset:UTF-8");
header("Content-Disposition: inline; attachment; filename=RegisterUser_$today.xls");
print "\n";
?>

A(Answer):

Not 100% sure about this but other users have reported problems downloading files in IE when setting the Cache-Control and Pragma headers.

Try commenting those lines out and running the file in IE to see if that is the issue. If it is you can use an if block to only set those headers for non-IE browsers.

A(Answer):

Thank you very much for your replay..I will try and get back to u..

A(Answer):

Your "Content-Disposition" header is malformed. It should be "inline" OR "attachment", not both. ("attachment" if you want the file downloaded, "inline" if you want it displayed.)

A(Answer):

I have removed inline from the line and updated it to

header("Content-Disposition: attachment; filename=RegisterUser_$today.xls");

But still it is not downloading wts the problem

A(Answer):

Ok, here are a few things to consider.
Most important thing when debugging: Turn on the error messages.. If you have them on, let us know so we won’t have to bug you about it. You are setting the Content-Type header four times, and the Cache-Control header twice. They should only be set once per response. (Excluding multi-part block headers.) You should only expect the response to include the latest value you set for any one header. (Meaning, you should consolidate/discard the other values.) The last Content-Type you use is set as: "Content-type: application/vnd.ms-excel;charset:UTF-8". The format for a header is supposed to be: "Content-Type: <type name>; charset=<charset>". (See the HTTP Header Field Definitions.) You need to fix your version, or browsers may be unable to parse it correctly. Whats with the print("\n"); command on the last line? If you are sending a file, you shouldn’t output anything other than the file data, or you risk corrupting it. Your session_cache_limiter(‘none’); call is invalid. The value "none" is not a valid parameter, and just causes the function to do nothing. The only valid values are: nocache, private, private_no_expire, or public. – You should try "nocache". If you plan on using the session_cache_limiter function, you should not manually set the Cache-Control, Expires, Last-Modified, or Pragma headers. The function will take care of that for you.

A(Answer):

Thank you for your replay.I made a many mistake in my coding.from your suggestion i corrected my coding like this


<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$today = date("d-m-Y");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header('Content-Description: File Transfer');
header("Content-type: application/vnd.ms-excel;");
header("Content-Disposition: attachment; filename=RegisterUser_$today.xls");
?>

But still it not coming in IE6 And IE7 its coming perfect in firefox and other browsers

LEAVE A COMMENT