微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 使用DOMDocument-> save(‘filename’)保存xml文件时出现问题

我有一个简短的PHP程序,它加载XML文件(test02.xml),然后尝试将其保存在另一个文件中.

该计划是:

<?PHP
//The next three lines are needed to open a file for writing on the server I use.

$stream_options = array('ftp' => array('overwrite' => TRUE));
$stream_context = stream_context_create($stream_options);
$fxml = fopen("ftp://userid:password@www.yurowdesigns.com/public_html/programs/test03.xml","w",0,$stream_context);

//The next three lines create a new DOMDocument, load the input file, "test02.xml"  
//and attempt to save the loaded file in the output file "test03.xml"

$doc = new DOMDocument;
$doc->load("test02.xml");
$doc->save("test03.xml");
?>

文件test03.xml正确打开,如果不存在则创建.但是,它没有输出.加载的文件test02.xml是非空的,格式良好的XML.我已经使用其他PHP程序成功加载并读取它.

当我运行上面的程序时,我收到消息:

警告:DOMDocument :: save(test03.xml)[domdocument.save]:无法打开流:第8行/home/yurow/wwwroot/yurowdesigns.com/programs/xmlTest.PHP中的权限被拒绝.

我在以下位置检查了’save’命令的语法:

PHPbuilder.com/manual/en/function.dom-domdocument-save.PHP

它似乎是正确的.知道是什么导致了这个???

解决方法:

尝试创建文件用户不是“yurow”(可能有权创建该文件用户).相反,它是一个用户,如“apache”或“httpd”.通常,系统设置为禁止apache / httpd用户在Web根目录中创建文件.这是为了安全目的而做的,我不建议通过给你的webroot提供apache / httpd写访问来绕过它.相反,您可以在/ home / yurow内部创建文档(只是不在/ home / yurow / wwwroot内).一个例子可能是:/home/yurow/xmldata/test02.xml.您可能需要调整此目录的权限以允许apache / httpd用户写入该目录.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐