Hi all,
The below code is used to download a excel file from the server.
However, my problem is that it won't open the file - In IE6 it gives the 'Unable to read file' error.
I believe this line is the problem...
list($name, $type, $size) = mysql_fetch_array($result);
$size doesn't seem to be set. When the pop-up download window appears asking me if I want to open or save the file it doesn't show the file size.
Tried moving that line into the while loop but only made a mess. The code works fine if getting file from database thus without the while loop.
Any ideas? Thanks.
// perform query
$query = "SELECT name, type, size FROM financial_statements ".
"WHERE id = '$id'";
$result = mysql_query($query) or die(mysql_error());
list($name, $type, $size) = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
if ($num_results > 0)
{
while($file = mysql_fetch_array($result))
{
// filepath
$uploaddir = 'admin/uploads/images/';
$uploadfile = $uploaddir . basename($file['name']);
echo 'Filename ('.$uploadfile.') '.$file['name'].'....<br />';
}
// Set Headers
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']))
{
// IE Bug in download name workaround
ini_set( 'zlib.output_compression','Off' );
}
header('Content-type: ' . $type);
header('Content-length: '. $size);
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Disposition: attachment; filename="' . $name . '"');
print($uploadfile);
exit;
}