Click to See Complete Forum and Search --> : Problem while downloading files ...


bee_kishore
01-30-2006, 06:09 AM
In my application iam trying to export employee details to excel file. Application is working fine but sometimes iam facing problems in IE. Following is the error message "IE cannot download from ...IE was not able to open this internet site. The required site is either unavailable or cannot be found.Please try later..."

moiseszaragoza
02-01-2006, 11:19 PM
I have this code that exports to excel with out a problem I Use IE all the time



<?php require_once('Connections_to_the_DB.php); ?>
<?php

// Query you will need to use your own
mysql_select_db();
$query_exelOrder = "SELECT * FROM Database_Table";
$exelOrder = mysql_query($query_exelOrder, $sarecino) or die(mysql_error());
$row_exelOrder = mysql_fetch_assoc($exelOrder);
$totalRows_exelOrder = mysql_num_rows($exelOrder);


$fields = mysql_num_fields($exelOrder);



for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($exelOrder, $i) . "\t";
}


while($row = mysql_fetch_row($exelOrder)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);


if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=filename_".date('D_F_d_Y_U').".xls"); // This prints a the name with the date and the Unnix code
header("Pragma: no-cache");
header("Expires: 0");



?>
<?php
print "$header\n$data";
mysql_free_result($exelOrder);
?>