我有一个简短的PHP程序,它加载一个XML文件(test02.xml),然后尝试将它保存在另一个文件中。使用DOMDocument-> save('filename')保存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:[email protected]/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程序成功加载并读取它。
当我运行上面的程序,我得到的消息:
警告:DOM文档保存::(test03.xml)[domdocument.save]:未能打开流:权限被拒绝的/ home/yurow/
phpbuilder.com/manual/en/function.dom-domdocument-:wwwroot的/ yurowdesigns.com /方案/ xmlTest.php上线8
我已经在检查了 '保存' 命令的语法save.php
它看起来是正确的。任何想法是什么造成这个?
@ user1107199听起来像/ home/yurow是使用ftp查看时的“/”根级别。所以,您可以简单地在wwwroot目录旁边创建xmldata目录。换句话说,查看/在你的ftp客户端中,你会看到/ wwwroot和/ xmldata(以及你在其中的任何其他东西) – 2012-01-10 13:33:35
我创建了文件夹/ XMLFiles,并成功创建了文件test03.xml和fopen()声明如下: $ fxml = fopen(“ftp:// userid:password!@ www.yurowdesigns.com/XMLFiles/test03.xml”,“w”,0,$ stream_context); (第10行)$ doc-> save(“/ home/yurow/XMLFiles/test03.xml”); 但是,上面的save()命令继续产生警告消息:警告:DOMDocument :: save(/home/yurow/XMLFiles/test03.xml)[domdocument.save]:未能打开流:拒绝/ home中的权限/yurow/wwwroot/yurowdesigns.com/programs/xmlTest.php在第10行。它看起来像这个婴儿被锁定紧! – user1107199 2012-01-11 02:19:25
@ user1107199我不明白你为什么要通过ftp创建文件,然后在本地读取它。假设你有这样做的理由,你可以尝试在脚本的顶部添加一个umask调用。例如的umask(0000)。和/或确保XMLFiles目录已设置,以便您和Apache用户可以读取/写入它。 – 2012-01-12 01:44:48