php – 使用DOMDocument-> save(‘filename’)保存xml文件时
发布时间:2020-12-13 17:10:20 所属栏目:PHP教程 来源:网络整理
导读:我有一个简短的 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));$st
我有一个简短的
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",$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用户写入该目录.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |