problem with this code
Posted: Wed May 12, 2004 9:04 pm
Code: Select all
<?php
ob_start();
require_once('../includes/mysql.inc');
$sql = "select username, userid, email, address from user";
$result = mysql_query($sql);
$delimiter = ",";
$quote = '"';
$csv = "";
while ($row = mysql_fetch_assoc($result)) {
$first = true;
foreach ($row as $field) {
if (!$first) $csv .= $delimiter;
$field = preg_replace("/"/", """, $field);
$csv .= $quote.$field.$quote;
$first = false;
}
$csv .= "\n";
}
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 5.5")) {
$att = "";
} else {
$att = " attachment";
}
header('Content-Type: application/download; name="export_new.csv"');
header('Content-Disposition:'.$att.' filename="export_new.csv"');
header('Content-Transfer-Encoding: binary');
echo $csv;
mysql_close();
ob_flush();
?>