ckfinder показывает сообщение «невозможно загрузить файл», но все еще сохраняет в папке - PullRequest
0 голосов
/ 16 марта 2020

Я использую ckfinder на ckeditor для загрузки изображения. Изображение правильно сохраняется через контроллер laravel, но я получаю всплывающее сообщение «Не удается загрузить файл». Изображение временно отображается в форме и затем скрывается после нажатия кнопки «ОК» в сообщении. Я часами просматривал документацию и безуспешно пробовал разные варианты конфигурации. Пожалуйста, помогите мне определить ошибку.
Это код моей формы:

import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

export default function ArticuloForm(props) {       
    const handleShow = () => setShow(true);
                    const onSubmit = data => {
                        let formData = new FormData();
                        let details = JSON.stringify(data);
                        formData.append('data', details);
                    if (props.data.imagen) formData.append('image', 
                        props.data.imagen, 
                        props.data.imagen.name);
                        const result = axios
                            .post('http://www.localhost/api/saveArticulo', 
                            formData)

                        return setMounted(false);
                    };

                    return (
                        <div className="container mt-5">
                            <div className="row">
                                <div className="col-xl-3 col-lg-4 col-md-6 col-sm-6 offset-4">
                                                                        </div>
                            </div>
                            <div className="row">
                                <div className="col-md-12"></div>
                                <CKEditor
                                    editor={ClassicEditor}
                                    data={content || ''}
                                    onInit={editor => {
                                        console.log('Editor is ready to use!', editor);
                                    }}
                                    onChange={(event, editor) => {
                                        const data = editor.getData();
                                        setContent(data);
                                        setDirty(true);
                                    }}
                                    config={{
                                        ckfinder: {
                                            uploadUrl: 'http://www.localhost/api/ckUpload',
                                        },
                                    }}
                                />
                            </div>
                        </div>
                    );
                }


        This is the ckfinder.php configuration file where I have changed settings without success.

                <?php
                // Development
                 error_reporting(E_ALL);
                 ini_set('display_errors', 1);

                $config = array();

                //$config['authentication'] = '\CKSource\CKFinderBridge\CKFinderMiddleware';
                $config['authentication'] = function() {
                     return true;
                };
                /*============================ License Key ============================================*/
                // http://docs.cksource.com/ckfinder3- 
               //  php/configuration.html#configuration_options_licenseKey    
                $config['licenseName'] = '';
                $config['licenseKey']  = '';

                /*============================ CKFinder Internal Directory ============================*/
                // http://docs.cksource.com/ckfinder3-
                //php/configuration.html#configuration_options_privateDir

                $config['privateDir'] = array(
                    'backend' => 'laravel_cache',
                    'tags'    => 'ckfinder/tags',
                    'cache'   => 'ckfinder/cache',
                    'thumbs'  => 'ckfinder/cache/thumbs',
                    'logs'    => array(
                        'backend' => 'laravel_logs',
                        'path'    => 'ckfinder/logs'
                    )
                );

                /*============================ Images and Thumbnails ==================================*/
                // http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_images

                $config['images'] = array(
                    'maxWidth'  => 1600,
                    'maxHeight' => 1200,
                    'quality'   => 80,
                    'sizes' => array(
                        'small'  => array('width' => 480, 'height' => 320, 'quality' => 80),
                        'medium' => array('width' => 600, 'height' => 480, 'quality' => 80),
                        'large'  => array('width' => 800, 'height' => 600, 'quality' => 80)
                    )
                );

                /*=================================== Backends ========================================*/
                // http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_backends
                $config['backends']['laravel_cache'] = array(
                    'name'         => 'laravel_cache',
                    'adapter'      => 'local',
                    'root'         => storage_path('framework/cache')
                );

                $config['backends']['laravel_logs'] = array(
                    'name'         => 'laravel_logs',
                    'adapter'      => 'local',
                    'root'         => storage_path('logs')
                );

                // Backends
                $config['backends']['default'] = array(
                    'name'         => 'default',
                    'adapter'      => 'local',
                    'baseUrl'      => 'http://www/localhost/public/images',
                    'root'         => public_path('/public/images'),
                    'chmodFiles'   => 0777,
                    'chmodFolders' => 0755,
                    'filesystemEncoding' => 'UTF-8'
                );

                /*================================ Resource Types =====================================*/
                // http://docs.cksource.com/ckfinder3-
                //php/configuration.html#configuration_options_resourceTypes

                $config['defaultResourceTypes'] = '';

                $config['resourceTypes'][] = array(
                    'name'              => 'Files', // Single quotes not allowed.
                    'directory'         => 'files',
                    'maxSize'           => 0,
                    'allowedExtensions' => '7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip',
                    'deniedExtensions'  => '',
                    'backend'           => 'default'
                );

                $config['resourceTypes'][] = array(
                    'name'              => 'Images',
                    'directory'         => 'images',
                    'maxSize'           => 0,
                    'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
                    'deniedExtensions'  => '',
                    'backend'           => 'default'
                );

                $config['roleSessionVar'] = 'CKFinder_UserRole';

                $config['accessControl'][] = array(
                    'role'                => '*',
                    'resourceType'        => '*',
                    'folder'              => '/',
                    'FOLDER_VIEW'         => true,
                    'FOLDER_CREATE'       => true,
                    'FOLDER_RENAME'       => true,
                    'FOLDER_DELETE'       => true,
                    'FILE_VIEW'           => true,
                    'FILE_UPLOAD'         => true,
                    'FILE_RENAME'         => true,
                    'FILE_DELETE'         => true,
                    'IMAGE_RESIZE'        => true,
                    'IMAGE_RESIZE_CUSTOM' => true
                );

                $config['overwriteOnUpload'] = false;
                $config['checkDoubleExtension'] = true;
                $config['disallowUnsafeCharacters'] = false;
                $config['secureImageUploads'] = true;
                $config['checkSizeAfterScaling'] = true;
                $config['htmlExtensions'] = array('html', 'htm', 'xml', 'js');
                $config['hideFolders'] = array('.*', 'CVS', '__thumbs');
                $config['hideFiles'] = array('.*');
                $config['forceAscii'] = false;
                $config['xSendfile'] = false;

                $config['debug'] = true;

                $config['plugins'] = array();

                $config['cache'] = array(
                    'imagePreview' => 24 * 3600,
                    'thumbnails'   => 24 * 3600 * 365
                );

                $config['tempDirectory'] = sys_get_temp_dir();
                $config['sessionWriteClose'] = true;
                $config['csrfProtection'] = true;

                return $config;
...