laravel-tinymce-simple-imageupload icon indicating copy to clipboard operation
laravel-tinymce-simple-imageupload copied to clipboard

Deletion of image

Open rambo666 opened this issue 7 years ago • 1 comments

The package works like a charm. But there is an issue if it could be resolved I hope many people will be using this function. After I uploaded the Image on tinymce texteditor it gets uploaded to the server, However If I delete the image from the text editor the uploaded images stays on my server. Could you add a way to resolve this issue? There is a workaround using Javascipt where I can take the deleted image name on deletion of image and then remove it from the sever, However using javascript on the client side means people can delete any image if they know the name.

rambo666 avatar Apr 10 '18 11:04 rambo666

Javascript code for deletion tinymce image by using ajax tinymce.init({ ... setup: function (editor) { editor.on('init change', function () { editor.save();

    });
    editor.on('KeyDown',function (e){
        if ((e.keyCode == 8 || e.keyCode == 46) && editor.selection) { //for Backspace key and delete key pressed
            var selectedNode = editor.selection.getNode();
            const Imgaes = walkDom(selectedNode);
            for(let i=0;i<Imgaes.length;i++){
                    let getFileName = Imgaes[i].src;

                    getFileName = getFileName.split('/');
                    getFileName = getFileName[getFileName.length - 1]
                    PostImgDeletion(getFileName)
            }
        }
    }
});

function walkDom(start_element) { var arr=[]; // we can gather elements here var loop=function(element) { do{ // we can do something with element if(element.nodeName=="IMG") // do not include text nodes only images Nodes arr.push(element); if(element.hasChildNodes()) loop(element.firstChild); } while(element=element.nextSibling); } loop(start_element); //loop(start_elem.firstChild); // do not include siblings of start element return arr; }

ihtisham007 avatar Nov 02 '21 06:11 ihtisham007