How to upload an image and / or file to the database with symfony2 and doctrine?

0

Good morning.

My question is, how can I upload an image or a pdf file for example to the database, and then consult it to show it.

I thank you in advance for your answers.

public function newResidentAction(Request $request)
{
    $req = $request->get('userInfo');
    $em = $this->getDoctrine()->getManager();
    $formType = new ResidentType();
    $resident = new Resident();
    $form = $this->createForm($formType, $resident, array('em'=>$em));



    if ($form->handleRequest($request)->isValid()) {

        $resident = $form->getData();

        $media =$resident->getMedia(); //-> aqui tengo el archivo que me trajo el formulario desde el proveedor sonata.media.provider.file
                                       //-> pero lo que necesito es guardardo directamente en la base de datos sin guardarlo en el servidor 

        $em->persist($resident);
        $em->flush();
    }

    return $resident;
}
    
asked by devjav 05.07.2016 в 21:31
source

0 answers