src/Ffcms/Apps/Api/Ckeditor/Editor.php
public function actionUpload($type)
    {
        /** @var $loadFile \Symfony\Component\HttpFoundation\File\UploadedFile */
        $loadFile = App::$Request->files->get('upload');
        if ($loadFile === null || $loadFile->getError() !== 0)
            return $this->errorResponse(__('File upload failed'));

        // get file extension
        $fileExt = '.' . $loadFile->guessExtension();
        // check if this request type is allowed
        if ($this->allowedExt[$type] === null || !Any::isArray($this->allowedExt[$type]))
            throw new NativeException('Hack attempt');

        // check if this file extension is allowed to upload
        if (!Arr::in($fileExt, $this->allowedExt[$type])) {
            return $this->errorResponse(__('This file type is not allowed to upload'));
        }

        $date = Date::convertToDatetime(time(), 'd-m-Y');

        // create file hash based on name-size
        $fileNewName = App::$Security->simpleHash($loadFile->getFilename() . $loadFile->getSize()) . $fileExt;
        $savePath = Normalize::diskFullPath('/upload/' . $type . '/' . $date);
        // save file from tmp to regular
        $loadFile->move($savePath, $fileNewName);

        // generate URI of uploaded file
        $url = '/upload/' . $type . '/' . $date . '/' . $fileNewName;

        return App::$View->render('editor/load_success',
            [
                'callbackId' => (int)App::$Request->query->get('CKEditorFuncNum'),
                'url' => $url
            ],
            __DIR__);
    }
public function actionUpload($type)
    {
        /** @var $loadFile \Symfony\Component\HttpFoundation\File\UploadedFile */
        $loadFile = App::$Request->files->get('upload');
        if ($loadFile === null || $loadFile->getError() !== 0)
            return $this->errorResponse(__('File upload failed'));

        // get file extension
        $fileExt = '.' . $loadFile->guessExtension();
        // check if this request type is allowed
        if ($this->allowedExt[$type] === null || !Any::isArray($this->allowedExt[$type]))
            throw new NativeException('Hack attempt');

        // check if this file extension is allowed to upload
        if (!Arr::in($fileExt, $this->allowedExt[$type])) {
            return $this->errorResponse(__('This file type is not allowed to upload'));
        }

        $date = Date::convertToDatetime(time(), 'd-m-Y');

        // create file hash based on name-size
        $fileNewName = App::$Security->simpleHash($loadFile->getFilename() . $loadFile->getSize()) . $fileExt;
        $savePath = Normalize::diskFullPath('/upload/' . $type . '/' . $date);
        // save file from tmp to regular
        $loadFile->move($savePath, $fileNewName);

        // generate URI of uploaded file
        $url = '/upload/' . $type . '/' . $date . '/' . $fileNewName;

        return App::$View->render('editor/load_success',
            [
                'callbackId' => (int)App::$Request->query->get('CKEditorFuncNum'),
                'url' => $url
            ],
            __DIR__);
    }
public function actionUpload ( $ type ) { /** @var $loadFile \Symfony\Component\HttpFoundation\File\UploadedFile */ $ loadFile = App :: $ Request -> files -> get ( 'upload' ) ; if ( $ loadFile === null || $ loadFile -> getError ( ) !== 0 ) return $ this -> errorResponse ( __ ( 'File upload failed' ) ) ; // get file extension $ fileExt = '.' . $ loadFile -> guessExtension ( ) ; // check if this request type is allowed if ( $ this -> allowedExt [ $ type ] === null || ! Any :: isArray ( $ this -> allowedExt [ $ type ] ) ) throw new NativeException ( 'Hack attempt' ) ; // check if this file extension is allowed to upload if ( ! Arr :: in ( $ fileExt , $ this -> allowedExt [ $ type ] ) ) { return $ this -> errorResponse ( __ ( 'This file type is not allowed to upload' ) ) ; } $ date = Date :: convertToDatetime ( time ( ) , 'd-m-Y' ) ; // create file hash based on name-size $ fileNewName = App :: $ Security -> simpleHash ( $ loadFile -> getFilename ( ) . $ loadFile -> getSize ( ) ) . $ fileExt ; $ savePath = Normalize :: diskFullPath ( '/upload/' . $ type . '/' . $ date ) ; // save file from tmp to regular $ loadFile -> move ( $ savePath , $ fileNewName ) ; // generate URI of uploaded file $ url = '/upload/' . $ type . '/' . $ date . '/' . $ fileNewName ; return App :: $ View -> render ( 'editor/load_success' , [ 'callbackId' => ( int ) App :: $ Request -> query -> get ( 'CKEditorFuncNum' ) , 'url' => $ url ] , __DIR__ ) ; }
Upload files from ckeditor
@param string $type
@return string
@throws NativeException
@throws \Ffcms\Core\Exception\SyntaxException
Upload files from ckeditor