m23's avatar
Level 1

i need help how can i upload image in laravel tinymce me am getting HTTP ERROE 405 WITH THIS CODE

<script>

    var editor_config = {
        path_absolute : "public/postImage/",
        selector: "#textarea",
        height: 500,
    theme: 'modern',
    plugins: [
      'advlist autolink lists link image  charmap toc print preview hr anchor pagebreak fullpage',
      'searchreplace wordcount visualblocks visualchars code fullscreen',
      'insertdatetime media nonbreaking save table contextmenu directionality',
      ' template paste textcolor colorpicker textpattern imagetools responsivefilemanager'
    ],
    toolbar1: 'insertfile undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | forecolor backcolor fullscreen fullpage',
    toolbar2: ' styleselect | fontselect | fontsizeselect | responsivefilemanager | paste hr removeformat toc',
    fontsize_formats: '8pt 10pt 12pt 14pt 18pt 24pt 36pt 48pt 72pt',
    imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage imageoptions",
  api_key: '35587473bd0c6300d6dc',
  images_upload_base_path: '/public/postImage/',
    images_upload_credentials: true,
    paste_data_images: true,
    paste_as_text: true,
    images_upload_url: 'postAcceptor.php',
    skin: "lightgray",
    image_advtab: true,
    automatic_uploads: false,


    images_upload_handler: function (blobInfo, success, failure) {
    var xhr, formData;
    xhr = new XMLHttpRequest();
    xhr.withCredentials = false;
    xhr.open('POST', 'postAcceptor.php');

    xhr.onload = function() {
      var json;

      if (xhr.status != 200) {
        failure('HTTP Error: ' + xhr.status);
        return;
      }

      json = JSON.parse(xhr.responseText);

      if (!json || typeof json.location != 'string') {
        failure('Invalid JSON: ' + xhr.responseText);
        return;
      }

      success(json.location);
    };

    formData = new FormData();
    formData.append('file', blobInfo.blob(), blobInfo.filename());

    xhr.send(formData);
  }
    };

    tinymce.init(editor_config);

</script>

THIS postAcceptor.PHP

0 likes
2 replies
D9705996's avatar

postAcceptor.php isn't your URL so it's giving you a 405 error (it's your filename) .

Do php artisan route:list and find the correct POST route/url from the output and use this instead

siddharth_9's avatar

My question is the image is uploaded and saved in the folder in the server side in the given path but if a user uploads 5 images and deletes 4 images then I should delete 4 images from the folder in the given path.

please give me suggestion.

Please or to participate in this conversation.