I am trying to delete a file using an AJAX call. It should be simple enough, but for some reason I'm getting an error when trying to access $_SERVER['DOCUMENT_ROOT']
when using the AJAX
I set up a HTML form and there is no problem. Let me show the code
This is the PHP which should delete the image.
$photo_name = $_POST['photo'];
$cat_id = $_POST['cat_id'];
$original_path = $_SERVER['DOCUMENT_ROOT'].$photo_name;
if(file_exists($original_path))unlink($original_path);
$data['success']=true;
Running the jquery below returns syntax error: Unexpected Token
$.ajax({
type : 'POST',
url : "includes/json_delete_photo.php",
dataType : 'json',
data: {
'photo': $('#image_name').val(),
'cat_id': $("#category_id").val(),
},
success : function(data){
alert("done");
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("problem: " + errorThrown);
}
});
However, just using a HTML form to submit to json_delete_photo.php without AJAX works, and if I remove the use of $_SERVER['DOCUMENT_ROOT']
from my PHP, the AJAX doesn't return an error (but my image doesn't delete!!)
I've been scratching my head on this one, and I'm not sure how to send the root to the page.
Thanks for any help.