2010-04-23 82 views
3

我正在創建一個xml文件。當用戶生成這個文件時,我希望它用生成的內容打開一個下載文件對話框。沒有實際的文件,因爲它只是通過php生成的。任何想法如何做到這一點?php強制下載xml

回答

5

發送一個content-disposition attachment標題。

+0

你明明didnt閱讀我的文章。沒有實際的文件可讀。它只是發送到頁面,我不想創建一個文件只是能夠下載它生成的文件。 – ngreenwood6 2010-04-23 06:00:07

+0

@ngreen你顯然沒有閱讀鏈接的文章。設置所述頭部並回顯xml數據。 – Amarghosh 2010-04-23 06:06:37

+0

哦,不錯,我以爲你真的不得不分配它的文件...謝謝你的信息 – ngreenwood6 2010-04-23 06:14:40

0
header('Content-disposition: attachment; filename=advertise.xml'); 
header ("Content-Type:text/xml"); 
//output the XML data 
echo $xml; 
// if you want to directly download then set expires time 
header("Expires: 0"); 
+0

,請爲用戶理解添加一些說明 – Cris 2014-02-05 10:04:52