SimpleXML problem
Posted: Wed Jan 18, 2012 7:32 pm
Hey All,
I'm trying to set some variables to update an XML file on save. File upload->xml->flash->frontend. Here is my code so far
and my xml
So basically, i need to update the imageName, captionEn and captionFr attributes. My script right now opens the xml and finds the two nodes I want to find (shown above). But I can't figure out how to update an attribute and then save it to the file. My current script gives me the following error:
Warning: file_put_contents(../portfolio/images.xml) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/vhosts/BLANK/httpdocs/admin/editbanner.php on line 49
So would anybody be able to help me update and save those attributes? Thanks!
I'm trying to set some variables to update an XML file on save. File upload->xml->flash->frontend. Here is my code so far
Code: Select all
$file = '../portfolio/images.xml';
$xml = simplexml_load_file($file);
foreach($xml->imageSet[0] as $image):
if($image->attributes()->rel != ""):
$image->attributes()->test = 'this is just a test';
endif;
endforeach;
file_put_contents($file, $xml->asXml());
Code: Select all
<imagesXML>
<imageSet titleEn="overview" titleFr="survol">
<image imageName="../../uploads/bannerimageen/4-promoimage_en.jpg" captionEn="/en/page.php?p=mcalendar" captionFr="fr/page.php?p=ghfd" rel="hprb" test="" />
<image imageName="../../uploads/bannerimagefr/4-promoimage_fr.jpg" captionEn="/en/page.php?p=magelendar" captionFr="/fr/page.php?p=magealendar" rel="hprb" test="" />
</imageSet>
<imagesXML>
Warning: file_put_contents(../portfolio/images.xml) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/vhosts/BLANK/httpdocs/admin/editbanner.php on line 49
So would anybody be able to help me update and save those attributes? Thanks!