src/Phlexible/Bundle/MediaManagerBundle/Controller/UploadController.php
public function uploadAction(Request $request)
    {
        $folderId = $request->get('folder_id', null);

        try {
            $volumeManager = $this->get('phlexible_media_manager.volume_manager');
            $volume = $volumeManager->getByFolderId($folderId);
            $folder = $volume->findFolder($folderId);

            if (empty($folder)) {
                return new ResultResponse(
                    false,
                    'Target folder not found.',
                    [
                        'params' => $request->request->all(),
                        'files' => $request->files->all(),
                    ]
                );
            }

            if (!$request->files->count()) {
                return new ResultResponse(
                    false,
                    'No files received.',
                    [
                        'params' => $request->request->all(),
                        'files' => $request->files->all(),
                    ]
                );
            }

            $uploadHandler = $this->get('phlexible_media_manager.upload.handler');

            $cnt = 0;
            foreach ($request->files->all() as $uploadedFile) {
                /* @var $uploadedFile UploadedFile */

                $file = $uploadHandler->handle($uploadedFile, $folderId, $this->getUser()->getId());

                if ($file) {
                    ++$cnt;

                    $body = 'Filename: '.$uploadedFile->getClientOriginalName().PHP_EOL
                        .'Folder:   '.$folder->getName().PHP_EOL
                        .'Filesize: '.$file->getSize().PHP_EOL
                        .'Filetype: '.$file->getMimeType().PHP_EOL;

                    $message = MediaManagerMessage::create('File "'.$file->getName().'" uploaded.', $body);
                    $this->get('phlexible_message.message_poster')->post($message);
                }
            }

            return new ResultResponse(
                true,
                $cnt.' file(s) uploaded.',
                [
                    'params' => $request->request->all(),
                    'files' => $request->files->all(),
                ]
            );
        } catch (\Exception $e) {
            return new ResultResponse(
                false,
                $e->getMessage(),
                [
                    'params' => $request->request->all(),
                    'files' => $request->files->all(),
                    'trace' => $e->getTraceAsString(),
                    'traceArray' => $e->getTrace(),
                ]
            );
        }
    }
public function uploadAction(Request $request)
    {
        $folderId = $request->get('folder_id', null);

        try {
            $volumeManager = $this->get('phlexible_media_manager.volume_manager');
            $volume = $volumeManager->getByFolderId($folderId);
            $folder = $volume->findFolder($folderId);

            if (empty($folder)) {
                return new ResultResponse(
                    false,
                    'Target folder not found.',
                    [
                        'params' => $request->request->all(),
                        'files' => $request->files->all(),
                    ]
                );
            }

            if (!$request->files->count()) {
                return new ResultResponse(
                    false,
                    'No files received.',
                    [
                        'params' => $request->request->all(),
                        'files' => $request->files->all(),
                    ]
                );
            }

            $uploadHandler = $this->get('phlexible_media_manager.upload.handler');

            $cnt = 0;
            foreach ($request->files->all() as $uploadedFile) {
                /* @var $uploadedFile UploadedFile */

                $file = $uploadHandler->handle($uploadedFile, $folderId, $this->getUser()->getId());

                if ($file) {
                    ++$cnt;

                    $body = 'Filename: '.$uploadedFile->getClientOriginalName().PHP_EOL
                        .'Folder:   '.$folder->getName().PHP_EOL
                        .'Filesize: '.$file->getSize().PHP_EOL
                        .'Filetype: '.$file->getMimeType().PHP_EOL;

                    $message = MediaManagerMessage::create('File "'.$file->getName().'" uploaded.', $body);
                    $this->get('phlexible_message.message_poster')->post($message);
                }
            }

            return new ResultResponse(
                true,
                $cnt.' file(s) uploaded.',
                [
                    'params' => $request->request->all(),
                    'files' => $request->files->all(),
                ]
            );
        } catch (\Exception $e) {
            return new ResultResponse(
                false,
                $e->getMessage(),
                [
                    'params' => $request->request->all(),
                    'files' => $request->files->all(),
                    'trace' => $e->getTraceAsString(),
                    'traceArray' => $e->getTrace(),
                ]
            );
        }
    }
public function uploadAction ( Request $ request ) { $ folderId = $ request -> get ( 'folder_id' , null ) ; try { $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; $ volume = $ volumeManager -> getByFolderId ( $ folderId ) ; $ folder = $ volume -> findFolder ( $ folderId ) ; if ( empty ( $ folder ) ) { return new ResultResponse ( false , 'Target folder not found.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } if ( ! $ request -> files -> count ( ) ) { return new ResultResponse ( false , 'No files received.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } $ uploadHandler = $ this -> get ( 'phlexible_media_manager.upload.handler' ) ; $ cnt = 0 ; foreach ( $ request -> files -> all ( ) as $ uploadedFile ) { /* @var $uploadedFile UploadedFile */ $ file = $ uploadHandler -> handle ( $ uploadedFile , $ folderId , $ this -> getUser ( ) -> getId ( ) ) ; if ( $ file ) { ++ $ cnt ; $ body = 'Filename: ' . $ uploadedFile -> getClientOriginalName ( ) . PHP_EOL . 'Folder:   ' . $ folder -> getName ( ) . PHP_EOL . 'Filesize: ' . $ file -> getSize ( ) . PHP_EOL . 'Filetype: ' . $ file -> getMimeType ( ) . PHP_EOL ; $ message = MediaManagerMessage :: create ( 'File "' . $ file -> getName ( ) . '" uploaded.' , $ body ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( $ message ) ; } } return new ResultResponse ( true , $ cnt . ' file(s) uploaded.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } catch ( \ Exception $ e ) { return new ResultResponse ( false , $ e -> getMessage ( ) , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , 'trace' => $ e -> getTraceAsString ( ) , 'traceArray' => $ e -> getTrace ( ) , ] ) ; } }
Upload File.

@param Request $request

@return ResultResponse
@Route("", name="mediamanager_upload")
Upload File .