2

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) { } }
1
  • 1
    I can't use the form with Form builder because I already have 3 forms in the same page How is that a problem? Commented Apr 30, 2014 at 13:31

1 Answer 1

4

Set the encrypt type in your form

<form enctype="multipart/form-data" action="{{ path('innova_forum_multimodal_add_contribution_file', {id: id }) }}" method="post">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.