0
以下代碼無法提示下載xml文件。我如何設置$數據之前的頭,因爲我得到了如下警告: 「警告:不能更改頭信息 - 頭已經發出」編寫一個xml文件並強制用php下載
private function display() {
$data ="some string";
$my_file = "sample.xml"; // name of file to be downloaded
$handle = fopen($my_file, "w");
fwrite($handle, $data);
fclose($handle);
header('Content-Type: text/xml');
header('Content-Disposition: attachment; filename='.basename($my_file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($my_file));
readfile($my_file);
exit;
}
Here is my ajax function
$.ajax({
url: "webservices/rest_api/display",
type: "POST",
success: function(result) {
console.log(result);
}
});
沒有路易斯似乎並沒有工作。感謝您及時的回覆!! – suna