Controller/UploadController.php
public function uploadAction(Request $request)
    {

        //return new JsonResponse($request);
        #var_dump($request);
        // process the filebag

        $rawMedias = array_merge(
            $this->processUploadedFiles($request->files),
            $this->processUrls($request)
        );

        $em = $this->getDoctrine()->getManager();
        $mtm = $this->get('mm_media.mediatype.manager');

        $returnData = array();

        foreach ($rawMedias as $rawmedia) {
            if (null != ($mt = $mtm->getMediaTypeMatch($rawmedia))) {

                /** @var MediaInterface $ms */
                $ms = $mt->getEntity();
                $em->persist($ms);

                $em->flush();

                $returnData[] = array(
                    'id' => $ms->getId(),
                    'path' => $rawmedia,
                    'mediatype' => (string) $ms->getMediaType(),
                );
            }
        }

        return new JsonResponse(
            array(
                'success' => true,
                'data' => $returnData,
            )
        );
    }
public function uploadAction(Request $request)
    {

        //return new JsonResponse($request);
        #var_dump($request);
        // process the filebag

        $rawMedias = array_merge(
            $this->processUploadedFiles($request->files),
            $this->processUrls($request)
        );

        $em = $this->getDoctrine()->getManager();
        $mtm = $this->get('mm_media.mediatype.manager');

        $returnData = array();

        foreach ($rawMedias as $rawmedia) {
            if (null != ($mt = $mtm->getMediaTypeMatch($rawmedia))) {

                /** @var MediaInterface $ms */
                $ms = $mt->getEntity();
                $em->persist($ms);

                $em->flush();

                $returnData[] = array(
                    'id' => $ms->getId(),
                    'path' => $rawmedia,
                    'mediatype' => (string) $ms->getMediaType(),
                );
            }
        }

        return new JsonResponse(
            array(
                'success' => true,
                'data' => $returnData,
            )
        );
    }
public function uploadAction ( Request $ request ) { //return new JsonResponse($request); #var_dump($request); // process the filebag $ rawMedias = array_merge ( $ this -> processUploadedFiles ( $ request -> files ) , $ this -> processUrls ( $ request ) ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ mtm = $ this -> get ( 'mm_media.mediatype.manager' ) ; $ returnData = array ( ) ; foreach ( $ rawMedias as $ rawmedia ) { if ( null != ( $ mt = $ mtm -> getMediaTypeMatch ( $ rawmedia ) ) ) { /** @var MediaInterface $ms */ $ ms = $ mt -> getEntity ( ) ; $ em -> persist ( $ ms ) ; $ em -> flush ( ) ; $ returnData [ ] = array ( 'id' => $ ms -> getId ( ) , 'path' => $ rawmedia , 'mediatype' => ( string ) $ ms -> getMediaType ( ) , ) ; } } return new JsonResponse ( array ( 'success' => true , 'data' => $ returnData , ) ) ; }
retrieves and handles the ajax upload action
to store uploaded files on file system.

@param Request $request

@return JsonResponse
retrieves and handles the ajax upload action to store uploaded files on file system .