How to save an XML file on the web server using PHP? -
I am making a beginning in PHP and I do not know anything about XML manipulation. I am working on the Google CSE Annotation XML shown below:
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; - & lt; Annotation & gt; - & lt; Comment about = "http://sanspace.in/" & gt; & Lt; Label name = "_ cse_byxamvbyjpc" /> & Lt; / Annotation & gt; - & lt; About annotation = "http://blog.sanspace.in/" & gt; & Lt; Label name = "_ cse_byxamvbyjpc" /> & Lt; / Annotation & gt; - & lt; Comment about "http://google.com/" & gt; & Lt; Label name = "_ cse_exclude_byxamvbyjpc" /> & Lt; / Annotation & gt; & Lt; / Annotation & gt;
I want to receive this with the file shown above:
& Lt; / Annotation & gt; - & lt; About annotation = "http://blog.sanspace.in/" & gt; & Lt; Label name = "teststring2" /> & Lt; / Annotation & gt; - & lt; Comment about "http://google.com/" & gt; & Lt; Label name = "teststring2" /> & Lt; / Annotation & gt; & Lt; / Annotation & gt;
So far I have tried:
annotation as $ annotation) {if ($ annotation ["about"] == "http://sanspace.in/") {$ annotation-> Label ["name"] = "testString1"; } And {$ annotation-> label ["name"] = "teststring2"; }} $ Dom = new DOMDocument ('1.0'); $ Dom- & gt; Protected WhiteSpace = false; $ Dom- & gt; FormatOutput = true; $ Dom- & gt; LoadXML ($ xml-> asXML ()); Echo $ dom- & gt; SaveXML (); $ Dom- & gt; Save ("test.xml"); ? & Gt;
This code works but it is not saved in the file.
My question is, that $ dom-> Save ("test.xml");
statement? How do I save the XML file to the server?
I do not see anything wrong in your code. I think your permission is a problem.
PHP is running as one of the following two users:
-
any
or possiblywww
- Your username
To run PHP as a user, which is the web root owner (i.e. you), suexec should be enabled for PHP. The fact is that you can not write in a file with the
0644
permissions, much more say it is not.You have two options:
- Reconfigure the server so that PHP can be run as a user who is the owner of a web root
- Make the file world friendly
I highly recommend the other before. However, you do not always have this option if your host (or sisamadmin, or anyone) can not enable suexec for PHP or not, then you must give the file
0777
permission, aliasrwxrwxrwx
.You want to log in via SSH and create an output file using the
touch
command (or the directory, if you do so, then youmkdir
needed), then give it the necessary permission. - Your username
Comments
Post a Comment