I am using the unlink()
method to the delete the file, but I think my syntax to get the string from my XML file is applying the wrong value. The file still remains undeleted but the good news is the script returns true and still removes the post from the XML.
My HTML form blog.php
sends the $_POST["CHECK"]
value:
<html>
<body>
<form method="post" action="remove_post.php">
<input type="hidden" name="CHECK" value="pst_02-02-2014_02:00:00pm" />
<input type="submit" name="CLOSE" value="Delete Post" />
</form>
</body>
</html>
My XML file: data.xml
<?xml version="1.0" encoding="UTF-8"?>
<blog>
<posting id="pst_01-01-2014_01:00:00pm">
<date>01-01-2014</date>
<time>01:00:00pm</time>
<title>Coming!</title>
<content>Blog Posts soon!</content>
</posting>
<posting id="pst_02-02-2014_02:00:00pm">
<date>02-02-2014</date>
<time>02:00:00pm</time>
<title>A Blog!</title>
<content>Blog Posts coming soon!</content>
<image>thumb.jpg</image>
</posting>
</blog>
My PHP file: remove_post.php
<?php
if ( isset( $_POST["CLOSE"] ) )
{
$check = $_POST["CHECK"] ;
$doc = new DOMDocument() ;
$doc -> load( "data.xml" ) ;
$xpath = new DOMXPath( $doc ) ;
$post_element = $xpath -> query( "/blog/posting[@id='$check']" ) ;
$image_element = $xpath -> query( "/blog/posting[@id='$check']/image" ) ; // Suspected problem
$image = "blog_images/" . $image_element -> firstChild ; // Suspected problem
foreach ( $post_element as $post )
{
unlink( $image ) ;
$post -> parentNode -> removeChild( $post ) ;
}
$doc -> save( "data.xml" ) ;
header( "Location: blog.php" ) ;
}
?>
...and yes I have checked my file permissions:
Folder (owner) permissions: /blog_images/
- read
- write
- execute
Folder (public) permissions:
- read
- execute
File (owner) permissions: thumb.jpg
- read
- write
File (public) Permissions:
- read