src/Controller/Admin/UploadController.php
public function ckeditorAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $funcNumber = $request->get('CKEditorFuncNum');

        if ($file = $request->files->get('upload')) {
            $supportedTypes = array(
                'image/jpeg',
                'image/png'
            );

            if ($file->getSize() > static::FILE_SIZE_MAX) {
                return $this->getCkeditorResponse(
                    'The uploaded file is too large. Please limit the file to under ' . (self::FILE_SIZE_MAX / 1024) . 'KiB',
                    '',
                    $funcNumber
                );
            }

            try {
                $uploadDir = $this->get('kernel')->getRootDir() . static::CKEDITOR_UPLOAD_DIR;
                $file      = File::createFromUploadedFile($file, $uploadDir);
                $file->moveUploadedFile();

                $em->persist($file);
                $em->flush();
            } catch (\Exception $e) {
                return $this->getCkeditorResponse($e->getMessage(), '', $funcNumber);
            }
        }

        if (!($file && file_exists($file->getPath()))) {
            return $this->getCkeditorResponse('There was an error while uploading the file. The file was not copied to the upload directory', '', $funcNumber);
        }

        $src = $this->generateUrl('file_view', array('id' => $file->getId()), true);

        return $this->getCkeditorResponse('Upload Successful', $src, $funcNumber);
    }
public function ckeditorAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $funcNumber = $request->get('CKEditorFuncNum');

        if ($file = $request->files->get('upload')) {
            $supportedTypes = array(
                'image/jpeg',
                'image/png'
            );

            if ($file->getSize() > static::FILE_SIZE_MAX) {
                return $this->getCkeditorResponse(
                    'The uploaded file is too large. Please limit the file to under ' . (self::FILE_SIZE_MAX / 1024) . 'KiB',
                    '',
                    $funcNumber
                );
            }

            try {
                $uploadDir = $this->get('kernel')->getRootDir() . static::CKEDITOR_UPLOAD_DIR;
                $file      = File::createFromUploadedFile($file, $uploadDir);
                $file->moveUploadedFile();

                $em->persist($file);
                $em->flush();
            } catch (\Exception $e) {
                return $this->getCkeditorResponse($e->getMessage(), '', $funcNumber);
            }
        }

        if (!($file && file_exists($file->getPath()))) {
            return $this->getCkeditorResponse('There was an error while uploading the file. The file was not copied to the upload directory', '', $funcNumber);
        }

        $src = $this->generateUrl('file_view', array('id' => $file->getId()), true);

        return $this->getCkeditorResponse('Upload Successful', $src, $funcNumber);
    }
public function ckeditorAction ( Request $ request ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ funcNumber = $ request -> get ( 'CKEditorFuncNum' ) ; if ( $ file = $ request -> files -> get ( 'upload' ) ) { $ supportedTypes = array ( 'image/jpeg' , 'image/png' ) ; if ( $ file -> getSize ( ) > static :: FILE_SIZE_MAX ) { return $ this -> getCkeditorResponse ( 'The uploaded file is too large. Please limit the file to under ' . ( self :: FILE_SIZE_MAX / 1024 ) . 'KiB' , '' , $ funcNumber ) ; } try { $ uploadDir = $ this -> get ( 'kernel' ) -> getRootDir ( ) . static :: CKEDITOR_UPLOAD_DIR ; $ file = File :: createFromUploadedFile ( $ file , $ uploadDir ) ; $ file -> moveUploadedFile ( ) ; $ em -> persist ( $ file ) ; $ em -> flush ( ) ; } catch ( \ Exception $ e ) { return $ this -> getCkeditorResponse ( $ e -> getMessage ( ) , '' , $ funcNumber ) ; } } if ( ! ( $ file && file_exists ( $ file -> getPath ( ) ) ) ) { return $ this -> getCkeditorResponse ( 'There was an error while uploading the file. The file was not copied to the upload directory' , '' , $ funcNumber ) ; } $ src = $ this -> generateUrl ( 'file_view' , array ( 'id' => $ file -> getId ( ) ) , true ) ; return $ this -> getCkeditorResponse ( 'Upload Successful' , $ src , $ funcNumber ) ; }
Handles ckeditor uploads

@Route("/ckeditor", name="ckeditor_upload", defaults={"_format"="json"})
@Secure(roles="ROLE_ADMIN")
Handles ckeditor uploads