I have a short PHP program that loads an XML file (test02.xml) and then attempts to save it in another file.
The program is:
<?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");
?>
The file test03.xml opens properly and is created if it does not exist. However, there is no output in it. The loaded file, test02.xml, is non-empty and well formed XML. I have loaded and read it successfully with other PHP programs.
When I run the above program, I get the message:
Warning: DOMDocument::save(test03.xml) [domdocument.save]: failed to open stream: Permission denied in /home/yurow/wwwroot/yurowdesigns.com/programs/xmlTest.php on line 8.
I have checked the syntax of the ‘save’ command at:
phpbuilder.com/manual/en/function.dom-domdocument-save.php
and it appears to be correct. Any idea what is causing this???
The user trying to create the file is not “yurow” (a user who likely has permission to create the file). Rather it’s a user such as “apache” or “httpd”. Often, systems are set up to disallow the apache/httpd user from creating files inside the web root. This is done for security purposes and I would not recommend trying to circumvent it by giving apache/httpd write access to your webroot. Instead, you could create the document somewhere inside /home/yurow (just not inside /home/yurow/wwwroot). An example might be: /home/yurow/xmldata/test02.xml. You may need to adjust permissions on this directory to allow the apache/httpd user to write to it.