File upload with Symfony3 not working

前端 未结 3 1371
星月不相逢
星月不相逢 2020-12-12 07:20

I am trying to upload file with Symfony3 but with no luck. I have a Profile entity which is linked to User entity with 1-1 relationship. The profile contains a picture colum

3条回答
  •  生来不讨喜
    2020-12-12 08:13

    Guys if you want to upload any kind of file in Symfony then I have very simple solution, which I have mentioned in the below. Why I am giving simple solutions because whenever new version come, you have to do some settings in services.yaml or you have to create extra files apart from your main controller.

    So solutions is: Just use move($storing_place, $actual_filename) function in your main controller.

    Put below codes in your controller file.

    $folder_path = 'public/uploads/brochures/';
    $file = $request->files->get('myfile');
    $fileName = $request->files->get('myfile')->getClientOriginalName();
    $file->move($folder_path, $fileName);        
    return new Response($file);
    

    Hope given solution will help in your project.

提交回复
热议问题