I have the following XML file called images.xml
Code:
<gallery timer="6" order="sequential" fadetime="3" looping="yes" xpos="0" ypos="0">
<image path="../flash/images/TEN_2.jpg" />
<image path="../flash/images/TEN_3.jpg" />
</gallery>
I want to be able to add another another image path to this file. So I wrote the following PHP code which is suppose to write another image path to the file.
PHP Code:
$file_contents = file_get_contents($_SERVER['DOCUMENT_ROOT']."/flash/images.xml");
$file_contents = str_replace ( '</gallery>', '', $file_contents); // delete gallery tag
$file_contents .= "<image path=\"../flash/images/$new_filename\" /></gallery>"; // Add new image path...then close with gallery tag
$fp = fopen($_SERVER['DOCUMENT_ROOT']."/flash/images.xml", 'w'); /// Open images.xml file
if(!$fp){
admin_top("Error", $user);
echo "There has been an error opening the flash/images.xml file.";
admin_footer();
exit();
}
fwrite($fp, $file_contents); // Write to XML file
fclose($fp); /// close file
The problem is that the new image path does not write to the file correctly. This is what the XML file will look like after I run the script:
Code:
<gallery timer="6" order="sequential" fadetime="3" looping="yes" xpos="0" ypos="0">
<image path="../flash/images/TEN_2.jpg" />
<image path="../flash/images/TEN_3.jpg" />
<image pat
I narrowed the problem down to the quotes at this line:
PHP Code:
$file_contents .= "<image path=\"../flash/images/$new_filename\" /></gallery>";
If I take the quotes away like the following:
PHP Code:
$file_contents .= "<image path=../flash/images/$new_filename /></gallery>";
Then the script will work correctly and the image path will write to the file but with no quotes so the Flash script will not work.
So the problem comes down to the quotes causing the problem. Anyone know a way to get around this problem...or know a better way to write the script?
Bookmarks