Upon upload, each physical image is saved in the following file structure:
UploadedFiles/userid/locationid/image
The image details i.e description, filename etc are saved in an XML file called 'files.xml' which is in the same location as the images. An extract of which can be seen below.
$nodeToRemove = null;
foreach ($list as $domElement){
$attrValue = $domElement->getAttribute('file_name');
if ($attrValue == 'image') {
$nodeToRemove = $domElement;
}
}
if ($nodeToRemove != null)
$thedocument->removeChild($nodeToRemove);
echo $doc->saveXML();
?>
With this, I can succesfully delete the physical image, but what I'm having great difficulty in doing is deleting the corresponding child node in the XML file.
I really quite new to dealing with XML but I've been working on this for weeks now, and I'm still no further forward.
I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong.
A few things jump out at me here. First, in the xml snippet you provided I do not see anywhere that you have an attribute by the name of 'file_name' which you are looking for in your php file:
Hi, thank you very much for taking the time to respond to my post, it is greatly appreciated.
You can probably tell, that I'm a complete beginner when it comes to XML.
I've made the changes you suggested, but unfortunately although the deletion of the physical image still works, I'm unable to get the corresponding node to be deleted.
I just wondered whether it would be at all possible for you to offer a little more guidance please.
Realising that the 'image' value carried forward the whole file path rather than just the file name of the image, I had to first break the file path down, then open the file and make the necessary changes to the XML file.
My solution is as follows:
PHP Code:
<?php session_start();
if (!empty($_POST)) {
$originalimage = $_POST['image'];
if (file_exists($originalimage)) {
unlink($originalimage);
}
}
Bookmarks