|
Posted by Simon Rigby on 07/13/06 01:08
Hi folks,
I appreciate that this topic of forced downloads has been discussed in
various threads but my situtation is a little different to those that I
have come across and am experiencing a wierd issue in IE6.
Essentially I am executing a select query against a MySql database and
taking the result of that query and building a csv stream on the fly to
send to the browser as a forced download.
I have a function which has been cobbled together from a few internet
sources. Code below:
function ForceDownload ($data, $name, $filesize=false) {
if ($filesize == false OR !is_numeric($filesize)) {
$filesize = strlen($data);
}
$mimetype = 'application/force-download';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,
pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename=\"" . $name .
"\";" );
echo $data;
die();
}
I am calling it from my page like so:
$result = GetContacts($searchTerm, $searchType);
$data = '';
while($row = mysql_fetch_assoc($result)) {
$data .= $row['ContactName'] . ',' . $row['Email'];
}
ForceDownload($data, 'contactExport.csv');
This works fine in Firefox but IE6 refuses to do anything at all. It
doesn't even display the content of the stream inline (ie in the
browser window).
Any ideas greatly appreciated.
Simon
Navigation:
[Reply to this message]
|