[ckeditor4] filetools-respone-error

사용한 버전 ckeditor4.13.1

이미지를 업로드하면 파라미터값(CKEditorFuncNum 등)이 넘어오지 않고 filetools-respone-error 에러를 발생시킨다.

config.filebrowserUploadMethod: ‘form’ 옵션을 지정하면 된다.

<form action="upload.php">
    <textarea name="editor1" id="editor1" rows="10" cols="80">
            This is my textarea to be replaced with CKEditor.
    </textarea>
    <script>
        CKEDITOR.replace( 'editor1' , {
            filebrowserUploadUrl: 'upload.php',
            filebrowserUploadMethod: 'form'
        });
    </script>
</form>
#upload.php
<?php
if(isset($_FILES['upload']['name'])){
    $file = $_FILES['upload']['tmp_name'];
    $file_name = $_FILES['upload']['name'];
    $file_name_array = explode('.', $file_name);
    $extension = end($file_name_array);
    $new_image_name = rand().'.'.$extension;
    $allowed_extension = array('jpg', 'png', 'gif');
    if(in_array($extension, $allowed_extension)){
        $result = move_uploaded_file($file, 'upload/'.$new_image_name);
        $funcNum = $_GET['CKEditorFuncNum'];
        $url = 'upload/'.$new_image_name;
        $message = 'hello';
        echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum,'$url','$message');</script>";
    }
}
?>

https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-filebrowserUploadMethod

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다