Home > Archive > PHP SQL > September 2007 > problem saving an excel file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem saving an excel file
|
|
|
| i have a php script to convert a simple query into an excel format
file (tab delimited) which is called mysql-to-excel. on the author's
website when i click on the script i download an xls file, but when i
do the same on my server it just echos back the query without saving a
file. any ideas. here is the script:
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT * FROM information ORDER BY lastname";
$result = mysql_query($query) or die('Error, query failed');
$tsv = array();
$html = array();
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
}
$tsv = implode("\r\n", $tsv);
$html = "<table>" . implode("\r\n", $html) . "</table>";
$fileName = 'mysql-to-excel.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");
echo $tsv;
//echo $html;
include 'closedb.php';
?>
thank you very much,
GD
| |
| J.O. Aho 2007-09-09, 7:02 pm |
| GD wrote:
> i have a php script to convert a simple query into an excel format
> file (tab delimited) which is called mysql-to-excel. on the author's
> website when i click on the script i download an xls file, but when i
> do the same on my server it just echos back the query without saving a
> file. any ideas. here is the script:
This has much to do with mimetypes and how things are configured, by tradition
products from microsoft are quite bad when it comes to mimetypes. I suggest
you try with application/octet-stream which seems to be the one and only way
to force a microsoft product to always save a file instead of displaying them.
--
//Aho
|
|
|
|
|