2017-08-09 57 views
0

我使用TinyMCE的4從例如圖像上載,並選擇圖像後上傳我收到「HTTP錯誤:404」消息。Tinimce 4圖像上載投擲HTTP錯誤:404

我測試過的例子postAcceptor.php與發佈圖像文件和它的作品。 上發佈圖片我收到JSON響應的結果:

{"location":"/home/mylogin/domains/mydomain.com/public_html/projects/projectname/img/gallery/422.jpg"}

這是否正確與那些多餘的斜線? 我的初始化代碼:

 tinymce.init({ 
      selector: 'textarea.content', 
      plugins: 'image code', 
      toolbar: 'undo redo | link image | code', 
      // enable title field in the Image dialog 
      image_title: true, 
      automatic_uploads: true, 

      images_upload_url: 'postAcceptor.php', 
      images_upload_base_path: '/img/gallery/', 
      images_upload_credentials: true, 

      file_picker_types: 'image', 

      // and here's our custom image picker 
      file_picker_callback: function(cb, value, meta) { 
       var input = document.createElement('input'); 
       input.setAttribute('type', 'file'); 
       input.setAttribute('accept', 'image/*'); 
       input.onchange = function() { 
        var file = this.files[0]; 

        var reader = new FileReader(); 
        reader.readAsDataURL(file); 
        reader.onload = function() { 
         var id = 'blobid' + (new Date()).getTime(); 
         var blobCache = tinymce.activeEditor.editorUpload.blobCache; 
         var base64 = reader.result.split(',')[1]; 
         var blobInfo = blobCache.create(id, file, base64); 
         blobCache.add(blobInfo); 
         cb(blobInfo.blobUri(), { title: file.name }); 
        }; 
       }; 

       input.click(); 
      } 
     }); 

回答

1

你正在返回的JSON肯定看起來像服務器的硬盤上的位置。所以它需要將允許瀏覽器通過Web服務器獲取圖像的URL位置被變成src屬性的圖像。

+0

還是一樣。它改變了正常的URL,現在我得到: { 「位置」: 「HTTP:\/\ /本地主機\ /項目名稱\/IMG \ /畫廊\ /422.jpg」} –

+0

什麼在編輯器中的圖像結束src何時處理?您通常不會在協議或主機名稱中包含返回值。 –

+0

什麼都沒有。這只是這樣的:我選擇一個文件https://ibb.co/eQSuRa之後。 –

0

404引起的,因爲

images_upload_url: 'postAcceptor.php', 

我把它改成

images_upload_url: './js/tinymce/postAcceptor.php', 

工作就像一個魅力..