Forum Moderators: coopster
So from that thread, I found this code jatar_k (our beloved admin) created.
I took out some lines since I wasn't sure what they do. So this is what I am using:
download.php
<?
if($submit) {
include "my_db.php";
$content_file .= "first,last,email\r\n";
$sql = 'select * from categories';
$statement = mysql_query($sql);
while($row = mysql_fetch_array($statement)) {
$content_file .= $row['first'] . ',' . $row['last'] . ',' . $row['email'] . "\r\n";
}
$output_file = 'mygreatcsvfile.csv';
@ini_set('zlib.output_compression', 'Off');
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: none');
//This should work for IE & Opera
header('Content-Type: application/octetstream; name="' . $output_file . '"');
//This should work for the rest
header('Content-Type: application/octet-stream; name="' . $output_file . '"');
header('Content-Disposition: inline; filename="' . $output_file . '"');
echo $content_file;
exit();
}
?>
<form name="form1" method="post" action="download.php">
<input type="submit" name="submit" value="Download">
</form>
When I press the Download button, I get a File Download dialog window. The code works fine if I choose Save. I then can specify where to save the file. But when I choose Open, it wouldn't work. I will get a error message that says "Excel has detected that 'download.php' is a SYLK file, but cannot load it......."
header('Accept-Ranges: bytes');