I am trying to delete file from server in summernote, but always getting undefined src error.
Warning: Undefined array key "src" in C:\wamp64\www\
I searched around found this: Summernote - Delete image from server and more but none of them are working.
I tried var src = $(this).attr("src");
and .prop()
function no luck to pass url in src to php file.
This is how src url is :<img src="http://localhost/news/uploads/large/6dBUlfZZBW.webp">
Here is my setup :
$('#summernote').summernote({
height: 400,
callbacks: {
onImageUpload: function(files, editor, welEditable) {
sendFile(files[0], editor, welEditable);
},
onMediaDelete : function($target) {
console.log($target[0].src); //This adds full url of src into console on test.
deleteFile($target[0].src);
$target.remove();
}
}
});
And my delete function :
function deleteFile(src) {
var src = $(this).attr("src");
$.ajax({
data:src,
type: "POST",
url: "delete_summernote.php",
cache: false,
success: function(resp) {
console.log(resp);
console.log(src);
}
});
}
Simple php example :
if(isset($_FILES['src'])){
$url = $_FILES['src'];
unlink($url);
} else {
echo "Src not set.";
}
Solved : Just needed a simple function, no cahce, no attr etc. thanks guys.
function deleteFile(path) {
$.ajax({
url: "delete.php",
type: "POST",
data: {'path':path},
success: function(resp) {
alert(resp);
}
});
}