[Vuejs]-Ckeditor5 vue check the image already removed

0👍

I use this method, upload the images and save the URLs. When I send the content of editor also send the URLs and on the server i compare that the URLs are in the content of the editor and those that are not i delete the corresponding file.

Client:

onChange={ ( event, editor ) => {

  this.state.description = editor.getData();

  var vm = this

  var urls = Array.from( new DOMParser().parseFromString( editor.getData(), 'text/html' )
             .querySelectorAll( 'img' ) )
             .map( img => img.getAttribute( 'src' ) );

  urls.forEach(function(element) {
    if (String(element).length > 10) {
      if (vm.state.filesCKeditor.length > 0) {
        if(filter(vm.state.filesCKeditor, function(o) { return String(o) === String(element) }).length == 0)
         {
           vm.state.filesCKeditor.push(element)
         }
       }else{
         vm.state.filesCKeditor.push(element)
       }
     }
   });
}}

enter image description here

Server:

foreach (explode(',',$this->post('filesCKeditor')) as $value) {
  # code...
  if (!isset(explode($value,$this->post('content'))[1])) {
    print_r('false');//add code for delete image
  }
}

Leave a comment