2010-09-01 88 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);