I am trying to delete file from server in summernote, but always getting undefined src error.
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.";
}
Your delete file function has some wrong specifications so that is the reason it is not working. Correct If I am wrong!
var src = $(this).attr("src"); // you are specifying to select "src" attribute
But here :
deleteFile($target[0].src);
you are selecting source in function then variable src output will be underfined.
This is what I understand. I hope it will help if I am not wrong But I have tried it on my pc. But I don't have full code I could help you.