I create a form manually, I can retrieve the name of my file at my controller but I can't upload the file here is my form
<form action="{{ path('innova_forum_multimodal_add_contribution_file', {id: id }) }}" method="post">
Choisissez le fichier à deposer :
<input type="file" id="file" name="file" required="required"/>
<input type="reset" value="Annuler" class="btn btn-primary" />
<input type="submit" value="Valider" class="btn btn-primary"/>
</form>
here is my controller
$request = $this->getRequest();
if($request->getMethod() == 'POST')
{
$dir = $this->get('kernel')->getRootDir().'/../web/uploads/files/';
$name = "fichier";
foreach($request->files as $uploadedFile) {
$file = $uploadedFile->move($dir, $name);
}
I can't use the form with Form builder because I already have 3 forms in the same page thank you in advance
here is the result of
$file = $request->files->get('upload');
var_dump($file); // => NULL
var_dump($request->request->all());
/* OUTPUT
array(1) { ["file"]=> string(7) "php.ini" }
*/
var_dump($request->files);
// OUTPUT
//object(Symfony\Component\HttpFoundation\FileBag)#11 (1)
// { ["parameters":protected]=> array(0) { } }
在表单中设置加密类型
<form enctype="multipart/form-data" action="{{ path('innova_forum_multimodal_add_contribution_file', {id: id }) }}" method="post">
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.