I have a form in symfony with a <input type="file" id="appbundle_evento_brochure_upload" name="img_uploader_brochure" class="image_upload">
which is generated dynamically with javascript.
When debugging my request I can see
+request: ParameterBag {#9 ▼
#parameters: array:3 [▼
"par_1" => array:14 [▶]
"img_uploader_brochure" => "file_name.jpg"
]
}
+query: ParameterBag {#10 ▶}
+server: ServerBag {#14 ▶}
+files: FileBag {#13 ▼
#parameters: []
}
I'm using Symfony form builder like this: $form = $this->createForm(EventoType::class, $evento, [*custom options here*]);
where EventoType
is my custom type generated on my Evento
entity.
Why aren't my files in the request->files
section?
The problem here seems to be that this file is not passed in the request as a file but simply as a parameter.
How should I proceed in order to manage them as UploadedFile
?
表单是否具有 enctype="multipart/form-data" 属性?
You have to set this property in your form html tag:
enctype="multipart/form-data"
Or this way with twig:
{{ form_start(form, {'multipart': true}) }}
That way, you are allowing the form to upload files
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.