title: How to upload files in Symfony 3
body: <p>I followed this <a href="http://symfony.com/doc/current/controller/upload_file.html" rel="nofollow">doc</a> to add an <code>Upload File</code> on my form (see image). </p>
  
  <p>My form works and if I add a file in it (I have for example '47f1f107e3e9629a8f41a861ccf1737a.png') in my database. My problem now is I can't display this image.</p>
  
  <p>Bestiaire.php : </p>
  
  <pre><code>/**
   * @ORM\Column(type="string")
   *
   * @Assert\NotBlank(message="Please, upload the bestiaire brochure as a PDF file.")
   * @Assert\File(mimeTypes={ "image/png" })
   */
  private $brochure;
  
  public function getBrochure()
  {
      return $this-&gt;brochure;
  }
  
  public function setBrochure($brochure)
  {
      $this-&gt;brochure = $brochure;
  
      return $this;
  }
  </code></pre>
  
  <p>BestiaireType.php</p>
  
  <pre><code>    &lt;?php
  
      namespace Tolkien\BestiaireBundle\Form;
  
      use Symfony\Bridge\Doctrine\Form\Type\EntityType;
      use Symfony\Component\Form\AbstractType;
      use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
      use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
      use Symfony\Component\Form\Extension\Core\Type\SubmitType;
      use Symfony\Component\Form\Extension\Core\Type\TextareaType;
      use Symfony\Component\Form\Extension\Core\Type\TextType;
      use Symfony\Component\Form\FormBuilderInterface;
      use Symfony\Component\Form\FormEvent;
      use Symfony\Component\Form\FormEvents;
      use Symfony\Component\OptionsResolver\OptionsResolver;
      use Symfony\Component\Form\Extension\Core\Type\FileType;
  
  
      class BestiaireType extends AbstractType
      {
          public function buildForm(FormBuilderInterface $builder, array $options)
          {
              $builder
                  -&gt;add('date',                   DateTimeType::class)
                  -&gt;add('name',                   TextType::class)
                  //etc..
                  -&gt;add('brochure',               FileType::class, array('label' =&gt; 'Brochure (PDF file)'))
                  -&gt;add('save',                   SubmitType::class);
  
  
              $builder-&gt;addEventListener(
                  FormEvents::PRE_SET_DATA,  
                  function(FormEvent $event) {
                      $bestiaire = $event-&gt;getData();
  
                      if (null === $bestiaire) {
                          return;
                      }
                  }
              );
          }
          public function configureOptions(OptionsResolver $resolver)
          {
              $resolver-&gt;setDefaults(array(
                  'data_class' =&gt; 'Tolkien\BestiaireBundle\Entity\Bestiaire'
              ));
          }
      }
  In my form : 
  
      {{ form_row(form.brochure) }}
  
  My controller :
  /**
   * @Security("has_role('ROLE_AUTEUR') or has_role('ROLE_USER') or has_role('ROLE_ADMIN') ")
   */
  public function addAction(Request $request)
  {
      $bestiaire = new Bestiaire();
      $form = $this-&gt;get('form.factory')-&gt;create(BestiaireType::class, $bestiaire);
  
  
  
      if ($request-&gt;isMethod('POST') &amp;&amp; $form-&gt;handleRequest($request)-&gt;isValid()) {
          /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
          $file = $bestiaire-&gt;getBrochure();
  
          $fileName = md5(uniqid()) . '.' . $file-&gt;guessExtension();
  
          $file-&gt;move(
              $this-&gt;getParameter('brochures_directory'),
              $fileName
          );
  
          $bestiaire-&gt;setBrochure($fileName);
  
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($bestiaire);
          $em-&gt;flush();
  
          $request-&gt;getSession()-&gt;getFlashBag()-&gt;add('notice', 'Annonce bien enregistrée.');
  
          return $this-&gt;redirectToRoute('tolkien_bestiaire_view', array('id' =&gt; $bestiaire-&gt;getId()));
      }
      return $this-&gt;render('TolkienBestiaireBundle:bestiaire:add.html.twig', array(
          'form' =&gt; $form-&gt;createView(),
      ));
  
  }
  </code></pre>
  
  <p>Config.yml :</p>
  
  <pre><code>parameters:
      locale: fr
      brochures_directory: '%kernel.root_dir%/web/uploads/brochures'
  </code></pre>
  
  <p>My vews : </p>
  
  <pre><code>&lt;li&gt;&lt;img src="{{ asset('uploads/brochures/' ~ bestiaire.brochure) }}"/&gt;&lt;/li&gt;
  </code></pre>