我有一个脚本,当用户访问链接时会生成一个XML文件,如下所示:
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文件打印到浏览器,我需要做什么?
I have a script which generates an XML file when the user accesses the link like so:
domain.com/dirList.php
I would like to print the contents of the XML to the user at the end of the POST or GET request (have not implemented this yet). At the moment I am just viewing the link through a web browser.
This is the code I am using to print the file contents.
# Open XML file and print contents $filename = "test.xml"; $handle = fopen ($filename, "r"); $contents = fread ($handle, filesize ($filename)); fclose ($handle); print $contents;The problem is that it doesn't seem to be working. I think I might be either missing a header like this: ("Content-Type: text/xml"); or maybe my code is wrong.
What do I need to do to get the XML file to print to the browser?
最满意答案
你可以这样做:
header('Content-type: text/xml'); // set the correct MIME type before you print. readfile('test.xml'); // output the complete file.You can just do:
header('Content-type: text/xml'); // set the correct MIME type before you print. readfile('test.xml'); // output the complete file.更多推荐
发布评论