如何在 PHP 中将 XML 文件保存到本地文件系统(客户端)?
在我的网站中,我实现了以下功能:如果用户单击按钮,则会触发 PHP 函数,该函数生成 XML 文件(该 PHP 函数由 AJAX 调用)。一切都运行良好,但我想更改一件事:我不想在服务器计算机上创建 .XML 文件;我不想在服务器上创建 .XML 文件。相反,我希望提示用户在本地保存 .XML 文件。我该怎么做?我的 PHP 脚本目前如下所示:
$xml = new DOMDocument("1.0", "UTF-8");
$rootElement = $xml->appendChild($xml->createElement("SomeNodeName"));
...
// the following doesn't really work - xml doesn't get formatted :)
$xml->formatOutput = true;
// this creates the actual file and places it on server. that's not what i need
$xml->save("MyXMLfile.xml");
感谢您的帮助。
In my site, I have implemented the following functionality: If the user clicks on a button it triggers a PHP function which generates an XML file (that PHP function is called by AJAX). Everything is working well, but here's one thing I want to change: I don't want an .XML file to be created on the server machine; instead, I want the user to be prompted to save the .XML file locally. How do I do that? My PHP script currently looks like this:
$xml = new DOMDocument("1.0", "UTF-8");
$rootElement = $xml->appendChild($xml->createElement("SomeNodeName"));
...
// the following doesn't really work - xml doesn't get formatted :)
$xml->formatOutput = true;
// this creates the actual file and places it on server. that's not what i need
$xml->save("MyXMLfile.xml");
Thanks for all the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 Web 内容都有一个标头,因此如果您为 xml 文件指定标头(通过使用
header()
函数和适当的代码,它将起作用。这意味着做这样的事情:
Every web content has a header, so if you specify the header for an xml file (through the use of the
header()
function with the appropriate code it'll work.This would mean doing something like this: