0

I have been working on a project, using Summernote. My project is like a blog system and I need to upload contents and images.

I have checked the other posts here and other places and managed to insert images to the file with ajax where I want to save the images. However, when I am editing, an image is there but once I click "update button" (submit button in a form), the images won't be there anymore.

I also check the inspect and resource says

Request URL: http://localhost/cms/admin/includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG

This is the right path but after updating, I get a message like

Request URL: http://localhost/%22includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG/%22

Also status code says

Status Code: 403 Forbidden

Here is my code

$('#summernote').summernote({
  callbacks: {
      onImageUpload: function(files) {
          for(let i=0; i < files.length; i++) {
              $.upload(files[i]);
          }
      }
  },
  height: 300,
});

$.upload = function (file) {
  let out = new FormData();
  out.append('file', file, file.name);

  $.ajax({
      method: 'POST',
      url: './includes/editor-upload.php',
      contentType: false,
      cache: false,
      processData: false,
      data: out,
      success: function(url) {
        $('#summernote').summernote("insertImage", url, 'filename');
      },
      error: function (jqXHR, textStatus, errorThrown) {
          console.error(textStatus + " " + errorThrown);
      }
  });
};

And this is my php code (editor-upload.php)

if ($_FILES['file']['name']) {
        if (!$_FILES['file']['error']) {
           $name = md5(rand(100, 200));
           $ext = explode('.', $_FILES['file']['name']);
           $filename = $name . '.' . $ext[1];
           $destination = 'images/' . $filename; //change this directory
           $location = $_FILES["file"]["tmp_name"];
           move_uploaded_file($location, $destination);
           echo 'includes/images/' . $filename;//change this URL
        }
        else
        {
         echo  $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['file']['error'];
        }
 }

Insert uploaded image to summernote editor Summernote image upload Summernote 0.8.12 Image Upload And Delete

I have tried these but nothing worked for me. I have of course Summernote js and css file and am using Summernote 0.8.18

I am sure I am doing something wrong but I can't figure this out yet.

I am hoping somebody can help me out.

0 Answers0