Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:04:49+00:00 2026-06-03T22:04:49+00:00

I wonder whether someone may be able yo help me please. I’ve put together

  • 0

I wonder whether someone may be able yo help me please.

I’ve put together this page which allows users to view a gallery of their uploaded images.

Upon initial upload, the physical images are saved in the following file structure:
UploadedFiles/userid/locationid/image and the details of the image i.e. description etc are saved in an xml file called files.xml which is in the same directory as the physical images.

I’m now working on allowing the user to be able to delete these images.

By way of a deletion icon under each image, I’ve, admitedly with some help, put together the following which successfully deletes the physical image.

‘Deletion Icon Onclick Event’

<script type="text/javascript"> 
    Galleria.ready(function() {
        this.$('thumblink').click();

    $(".galleria-image").append( 
    "<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
    $(".btn-delete").live("click", function(){
    var img = $(this).closest(".galleria-image").find("img"); 

    // send the AJAX request
    $.ajax({
    url : 'delete.php',
    type : 'post',
    data : { image : img.attr('src') },
    success : function(){
    alert('Deleting image... ');
    img.parent().fadeOut('slow');
    }
    });

    return false;
    });

    });

</script>

Original ‘delete.php’

<?php

if (!empty($_POST)) {
$image = $_POST['image'];

if (file_exists($image)) {
unlink($image);
} 
}
?>

Updated ‘delete.php’

<?php

if (!empty($_POST)) {
$image = $_POST['image'];

if (file_exists($image)) {
unlink($image);
} 
}

$doc = new DOMDocument; 
$doc->load('files.xml'); 

$thedocument = $doc->documentElement; 

$list = $thedocument->getElementsByTagName('files'); 

$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(); 
?> 

The problem I’m having is deleting the xml node form the xml file. I’ve provided an extract of the XML file below.

  <?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="stag.jpg" source="stag.jpg" size="21341" originalname="stag.jpg" description="No description provided" userid="1" locationid="1" /> 
  </files>

I’ve done quite a bit of research about how to go about this and found that jQuery had it’s own command i.e. jQuery.remove which I thought would be able to delete the node. Following the brief tutorial I added the following to the end of my ‘Onclick Event’ script:

var doc = $(files.xml);
doc.find('file_name:src').remove();

Unfortunately, although I don’t receive a specific error, the node isn’t being deleted from the file. I’m a complete beginner when it comes to XML so perhaps I’m looking at this too simplistically.

I just wondered wheteher someone could perhaps have a look at this please and let me know where I’m going wrong.

Many thanks and regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:04:51+00:00Added an answer on June 3, 2026 at 10:04 pm

    This is because JavaScript(JQuery) loads the XML DOM in memory and then when you delete a node,
    it gets deleted from the in-memory xml doc(the object).

    It wont be removed from the physical XML file.

    JS runs in a sandbox Browser environment and cannot alter local files on the system.
    and if you are trying to load xml from a remote server then its a very bad idea.

    the XML file from remote server is downloaded as temp file and then when you load XML again an in-memory DOM is created and the node is deleted from it.

    So in case you want the actual file to be changed,
    you will need to use AJAX and send some HTTP request to your server to do the same to the physical file.

    UPDATE:

    Check this tutorial
    http://www.phpeveryday.com/articles/PHP-XML-Removing-Node-P415.html

    and try to load the xml file in your delete.php and remove the corresponding node from it and then save this xml back to the original file which will be overwritten.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone can help me please. I've created this form which allows
I wonder whether someone may be able to help me please. I've put some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.