I'm trying to delete a file with jQuery's $.ajax
and php. I have the following.
/js/whatever.js
$('.deleteimage').live('click', function() {
$imagefile = 'http://domain.com/images/1/whatever.jpg';
$imagethumb = 'http://domain.com/images/1/thumbnail/whatever.jpg';
$.ajax({
type: 'POST',
data: {
action: 'deleteimage',
imagefile: $imagefile,
imagethumb: $imagethumb,
},
url: 'script.php',
success: function(msg) {
alert(msg);
}
})
})
/php/script.php
<?php
if($_GET["action"]=="deleteimage")
{
$imagefile = $_REQUEST['imagefile'];
$imagethumb = $_REQUEST['imagethumb'];
$imagefileend = '../images'.end(explode('images',$imagefile)); //This will get me the path to the image ../images/1/whatever.jpg without the domain which is the correct path to the file. I tried that path directly and it deleted the file.
$imagethumbend = '../images'.end(explode('images',$imagethumb));
unlink($imagefileend);
unlink($imagethumbend);
}
?>
All path are correct. In firebug i see the post variables are being sent correctly to script.php, however files are not being deleted. What am i doing wrong.