Error: MIME type text/csv
I am using jQuery to recognise a click on a button which then fires a call to a file:
window.location.href = "url";
This file queries the database, returns results then writes it to a CSV file. I have the following headers set:
header('Content-Type: text/csv;');
header('Content-Disposition: attachment; filename=data.csv');
This works on all browsers except Chrome which returns the following error in the console log "Resource interpreted as Document but transferred with MIME type text/csv: "url"".
The weird thing is that if I call the file directly it works in all browsers.
Code:
$fp = fopen('php://output', 'w');
header('Content-Type: text/csv;');
header('Content-Disposition: attachment; filename=data.csv');
header("Expires: 0");
header("Cache-control: private");
//Field Headers
$ncols = oci_num_fields($stid);
$headers_row = array();
for ($i = 1; $i <= $ncols; ++$i) {
$headers_row[] = oci_field_name($stid, $i);
}
while ($row = oci_fetch_array($stid, OCI_NUM+OCI_RETURN_NULLS)) {
if(!empty($row)){
if(!empty($headers_row)){
fputcsv($fp, $headers_row);
$headers_row = '';
}
fputcsv($fp, $row);
}
}
fclose($fp);
oci_close($conn);
Anyone got any ideas?
头(“content-type:application / force-download”);
header("Expires: 0");
header("Cache-control: private");
链接地址: http://www.djcxy.com/p/46854.html上一篇: 是一个MIME头声明良好的做法?
下一篇: 错误:MIME类型文本/ csv