2010-09-01 135 views
1

我有產生一個XML文件的腳本當用戶訪問像這樣的鏈接:輸出內容爲GET/POST請求

domain.com/dirList.php

我想在POST或GET請求結束時將XML的內容打印給用戶(尚未實現此功能)。目前我只是通過網絡瀏覽器查看鏈接。

這是我用來打印文件內容的代碼。

# Open XML file and print contents 
$filename = "test.xml"; 
$handle = fopen ($filename, "r"); 
$contents = fread ($handle, filesize ($filename)); 
fclose ($handle); 
print $contents; 

問題是它似乎沒有工作。我想我可能會錯過這樣的標題:("Content-Type: text/xml");或者也許我的代碼是錯誤的。

如何讓XML文件打印到瀏覽器需要做些什麼?

回答

0

你可以這樣做:

header('Content-type: text/xml'); // set the correct MIME type before you print. 
readfile('test.xml'); // output the complete file. 
0
//Check there is any extra space before <? and after ?> 

//or 

header('Content-type: text/xml'); 
echo file_get_contents($path.$xmlfile);