开发者

Output Contents of PHP File for a GET/POST request

开发者 https://www.devze.com 2023-01-14 14:48 出处:网络
I have a script which generates an XML file when the user accesses the link like so: domain.com/dirList.php

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 mis开发者_JAVA百科sing 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?


You can just do:

header('Content-type: text/xml'); // set the correct MIME type before you print.
readfile('test.xml'); // output the complete file.


//Check there is any extra space before <? and after ?>

//or 

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

精彩评论

暂无评论...
验证码 换一张
取 消