用于GET / POST请求的PHP文件的输出内容(Output Contents of PHP File for a GET/POST request)

编程入门 行业动态 更新时间:2024-10-26 14:38:34
用于GET / POST请求的PHP文件的输出内容(Output Contents of PHP File for a GET/POST request)

我有一个脚本,当用户访问链接时会生成一个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.

更多推荐

本文发布于:2023-07-09 02:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   内容   PHP   POST   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!