2017-11-17 6 views
0

이 질문은 여러 번 묻고 여러 가지 방법으로 모두 내 문제가 해결되었는지 의심 스럽습니다.예기치 않은 토큰 <위치 0의 JSON에서 tinymce

나는 파일 업 로더와 함께 TinyMCE을 사용합니다. URL을 사용하면 인터넷에서 다시 가져올 수 있기 때문에 작동합니다. 폴더에있는 이미지를 사용하고 싶으면 "이미지 업로드 : 100 %"이라는 상자 위에 TinyMCE의 이미지가 업로드됩니다. 그러나이 메시지는 맨 위에 머물러 있으며 모든 내용을 게시하면 이미지가 전송됩니다. 되돌아 보니 업로드 된 모든 이미지를 배치 할 파일 디렉토리에는 내용이 없습니다. 또한 오류가 발생했습니다.

위치 0의 JSON에서 예기치 않은 토큰 < : 오류를 찾아보고 재미있는 것을 발견했습니다. 그것은 내용이가는 길을 보여주었습니다.

move_uploaded_file(this_is_the_path/this_is_the_image.jpg) 

음이 예에서 잘 보이지만, 개발 도구에서 경로 문자열하지만 파일이 검은 색에서 주황색으로 표시됩니다. 여기에 문제가 있습니까? 내가 문자열에 싸서하고 명백한 결과였다

분명히 잘못
move_uploaded_file(this_is_the_path/'this_is_the_image.jpg') 

.

2 개의 문제가 관련되어 있지만 문제로 간주되는 순간 중요하지 않습니다.

일부 부품을 변경하는 경우. 어느 쪽인지 잘 모르겠다. VM'random number '에 위치한 오류에서부터 조치가 일어나고있는 frontpage로 이동합니다. 숫자로 시작

파일은 전혀 업로드되지 않고 오류로 메세지됩니다 주요 문제는 내가 그에 보이는 것 해결 한 후 500

.

내 경로를 처리하기위한 PHP 코드.

<?php 
    $accepted_origins = array("http://localhost:8080"); 
    $imageFolder = "uploaded_content_frontpage/"; 
    reset ($_FILES); 
    $temp = current($_FILES); 
    if (is_uploaded_file($temp['tmp_name'])){ 
     if (isset($_SERVER['HTTP_ORIGIN'])) { 
      if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) { 
       header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); 
      } else { 
       header("HTTP/1.0 403 Origin Denied"); 
       return; 
      } 
     } 

// Sanitize input 
     if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) { 
      header("HTTP/1.0 500 Invalid file name."); 
      return; 
     } 

// Verify extension 
     if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) { 
      header("HTTP/1.0 500 Invalid extension."); 
      return; 
     } 

     // Accept upload if there was no origin, or if it is an accepted origin 
     $filetowrite = 'uploaded_content_frontpage/'.$temp['name']; 
     move_uploaded_file($temp['tmp_name'], $filetowrite); 

     echo json_encode(array('location' => $filetowrite)); 
    } else { 
     // Notify editor that the upload failed 
     header("HTTP/1.0 500 Server Error"); 
    } 
?> 

는 경로 지정이 잘못인가 아니면 오타 또는 그것은 뭔가 다른?

$(document).ready(function() { 
tinymce.init ({ 
     theme: 'modern', 
     selector: '.add_body_structure', 
     height: 1000, 
     menubar: true, 
     branding: false, 
     toolbar: 'undo redo | styleselect bold italic forecolor backcolor fontselect fontsizeselect | link paste | alignleft aligncenter alignright alignjustify | outdent indent bullist numlist | removeformat | insert', 
     plugins: ' contextmenu print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media mediaembed template table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern help autoresize noneditable', 
     contextmenu: 'paste link image inserttable cell row column deletetable', 
     advlist_bullet_styles: 'square', 
     advlist_number_styles: 'lower-alpha,lower-roman,upper-alpha,upper-roman', 
     statusbar: false, 
     browser_spellcheck: true, 
     image_title: true,  
     automatic_uploads: true, 
     media_live_embeds: true, 
     contextmenu: true, 
     relative_urls: false, 
     remove_script_host: false, 
     paste_data_images: true, 
     encoding: 'xml', 
     invalid_elements: 'script, input, textarea, textfield, col, colgroup, caption, dir, meta, object, select, option, source, title', 
     fontsize_formats: '8pt 10pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 26pt 28pt 30pt 32pt 34pt 36pt 38pt 40pt', 
     images_upload_url: '/wysiwyg/tinymce_main/wysiwyg_one_page_version2.1/views/home/code_for_images/image_uploader.php', 

     file_picker_callback: function(cb, value, meta) { 
      var input = document.createElement('input'); 
      input.setAttribute('type', 'file'); 
      input.setAttribute('accept', 'image/*, audio/*, video/*'); 

      input.onchange = function() { 
       var file = this.files[0]; 

       var reader = new FileReader(); 
       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); 
        // call the callback and populate the Title field with the file name 
        cb(blobInfo.blobUri(), { title: file.name }); 
       }; 
       reader.readAsDataURL(file); 
      }; 
     input.click(); 
     } 

}); 
});  

은 경고 : 인 move_uploaded_file (uploaded_content_frontpage/blobid1510920245387.jpg) : C에서 해당 파일 또는 디렉터리 : 스트림을 열지 못했다 \ WAMP \ www가 \ WYSIWYG \ tinymce_main \ wysiwyg_one_page_version2.1 \ 전망 \ 홈 \ code_for_images \ image_uploader.php on line

라인 45는 move_uploaded_file ($ temp [ 'tmp_name'], $ filetowrite)을 나타냅니다.

알 수 있듯이 그러한 파일이 내 디렉토리에 없기 때문에 스트림을 열 수 없습니다.

+0

주석으로 "에코 $의 filetowrite"그 도움이된다면 .. 내가 전체 PHP 페이지가 정적 파일로 클라이언트로 전송있어 의심 .. – Azima

+0

를 참조 다시 시도에 적 해석되는 O/승 . 업로드 자체가 작동하는지 확인 했습니까? 또한 해당 페이지의 정확한 응답은 무엇입니까? – minmaxavg

+0

문제가 아직 남아 있습니까? – Azima

답변

0

파일 경로가 당신의 JSON 전에 반향, 그리고는 JSON 구문 분석 오류의 원인이 무엇되고 있기 때문에 밖으로

echo $filetowrite; 

및 확인 코멘트. 또한 추가로 '가 있습니다.'당신의

$filetowrite = 'uploaded_content_frontpage/'.$temp['name'].(see here); 
+0

그것을 지적 해 주셔서 감사합니다. 다음 번에 코드를 게시하기 전에 코드를 정리할 필요가 있습니다. 네가하는 말은 모두 실행 가능하다. 그것은 내가 시도한 것들의 남은 부분이었습니다. 어쨌든, 응답을위한 thx. 실제 BLOB 코드가 추가 된 실제 코드에 대한 편집을 참조하십시오. – Menazanie

+0

글쎄, 난 바보 야. PHP 코드를 다시 본 후에 내가 가고 싶었던 디렉토리가 존재하지 않는다는 것을 알았습니다. 그것은 내 PHP가 단지 그 목적을 위해 만든 다른 폴더 대신에 거짓말을 한 폴더 안에 저장되어 있습니다. – Menazanie