SimpleXML problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

SimpleXML problem

Post 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! :)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: SimpleXML problem

Post by Celauran »

Looks like Apache doesn't have write permission to the file/directory.
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

Re: SimpleXML problem

Post by invisibled »

sometimes you just need a forum member to slap you in the face. Thanks guy. :)
Post Reply