Page 1 of 1

SimpleXML problem

Posted: Wed Jan 18, 2012 7:32 pm
by invisibled
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

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());
and my xml

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>
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! :)

Re: SimpleXML problem

Posted: Thu Jan 19, 2012 6:53 am
by Celauran
Looks like Apache doesn't have write permission to the file/directory.

Re: SimpleXML problem

Posted: Thu Jan 19, 2012 12:29 pm
by invisibled
sometimes you just need a forum member to slap you in the face. Thanks guy. :)