所以,首先讓我說明,在開始提供其他關於如何將完整表格導出爲CSV文件的其他建議之前,我不想這麼做(我的演示代碼現在表明,但我只是通過瀏覽器shabaz測試整個下載)。CSV MIME類型的問題不通過瀏覽器下載
我實際上想構建我的內容從幾個表中導出。從來沒有,我只是試圖通過瀏覽器的出口和下載工作。
我從網上的一個例子中得到了這段代碼,目前發生的情況就是將數據打印到我的瀏覽器中。
這裏是我的代碼我測試:
$result = mysql_query("SELECT * FROM results_tb") or die(mysql_error());
// I hard-code the column names so I can capitalize, add spaces, etc.
$fields = '"User ID","Test_id","score %","Time taken"'."\n";
// Iterate through the rows of data
while ($row = mysql_fetch_assoc($result))
{
//echo $row['user_id'];
$fields .= '"'.$row['user_id'].'","'.$row['test_id'].'","'.$row['score'].'","'.$row['time_elapsed'].'"'."\n";
}
// Set our headers
header('Content-type: text/csv');
// To display data in-browser, change the header below to:
// header("Content-Disposition: inline");
header("Content-Disposition: attachment; filename=event_registrations.csv");
// Output our data
echo $fields;
我假定這例子是褲子,所以可能有人向我解釋如何做到這一點?
千恩萬謝:d
我的頭響應補時螢火蟲 - 精簡版:
Date Wed, 18 May 2011 14:15:18 GMT
X-Powered-By PHP/5.1.6
Content-disposition attachment;filename=MyVerySpecial.csv
Connection close
Content-Length 992
Server Apache/2.2.3 (Red Hat)
Content-Type text/csv
如果將內容類型更改爲應用程序/八位字節流,有任何更改?如果是這樣,那麼您的瀏覽器想要處理所有文本/ *類型並忽略處置。 – Mel 2011-05-18 13:27:48
嗨,謝謝,不幸的是,我得到同樣的東西。 – buymypies 2011-05-18 13:30:48