Assuming that you want to actually delete the file (and not just remove it from the DOM), either use Ajax or wrap your images with a link that is targeting a script to delete the file:
With Ajax:
<?
$xml = simplexml_load_file('myPhotos.xml');
//echo $xml->getName() . "<br />";
foreach ($xml->children() as $child)
{
echo '<img src="' . $child['src'] . '" alt="gallery image" onclick="deleteFile('.$child["src"].')" />';
}
?>
<script>
function deleteFile(filename) {
var t = this;
$.ajax({
url: 'deleteFile.php?filename='+filename,
type: 'post',
success: function(data) {
t.style.display = 'none';//hide the link
alert('File deleted!');
}
});
}
</script>
And on your deleteFile.php you will need to use:
$filename = $_GET['filename'];//gets the file name from the URL
unlink($filename);//deletes the file
Second option:
If you must keep everything with PHP and not use jQuery or Ajax, you can simply wrap the images with a link and set its href to:
echo '<a href="deleteFile.php?filename=' . $child["src"] . '"><img src="' . $child['src'] . '" alt="gallery image" /></a>';
Hope this helps