Uploaded file directory in Symfony 2.8
<p>I just made a file upload form in my project, thanks to Symfony documentation.
My project is in version 2.8.</p>

<p>In MySQL, I have my Media table with File for emplacement. I thought Symfony created a upload directory, but the link looks like this:</p>

<p>Media</p>

<pre><code>+---------+----+--------------+----------------+
| Libelle | ID | Cat_Media_ID | file           |
+---------+----+--------------+----------------+
| test    |  1 |            1 | /tmp/phpY0oLd6 |
+---------+----+--------------+----------------+
</code></pre>

<p>Is it normal? Should I specify the directory where files needs to be added?</p>

<p>EDIT 2:</p>

<p>My Media Entity:</p>

<pre><code>&lt;?php

namespace AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Media
 *
 * @ORM\Table(name="Media", indexes={@ORM\Index(name="fk_Media_Cat_Media1_idx", columns={"Cat_Media_ID"})})
 * @ORM\Entity
 */
class Media
{
    /**
     * @var string
     *
     * @ORM\Column(name="Libelle", type="string", length=45, nullable=true)
     */
    private $libelle;

    /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \AdminBundle\Entity\CatMedia
     *
     * @ORM\ManyToOne(targetEntity="AdminBundle\Entity\CatMedia")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Cat_Media_ID", referencedColumnName="ID")
     * })
     */
    private $catMedia;


    /**
     * @ORM\Column(type="string")
     *
     *
     * @Assert\File(mimeTypes={ "application/image" })
     */
    private $file;



    /**
     * Set libelle
     *
     * @param string $libelle
     * @return Media
     */
    public function setLibelle($libelle)
    {
        $this-&gt;libelle = $libelle;

        return $this;
    }

    /**
     * Get libelle
     *
     * @return string 
     */
    public function getLibelle()
    {
        return $this-&gt;libelle;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this-&gt;id;
    }

    /**
     * Set catMedia
     *
     * @param \AdminBundle\Entity\CatMedia $catMedia
     * @return Media
     */
    public function setCatMedia(\AdminBundle\Entity\CatMedia $catMedia = null)
    {
        $this-&gt;catMedia = $catMedia;

        return $this;
    }

    /**
     * Get catMedia
     *
     * @return \AdminBundle\Entity\CatMedia 
     */
    public function getCatMedia()
    {
        return $this-&gt;catMedia;
    }



    public function setFile($file)
    {
        $this-&gt;file = $file;

        return $this;
    }


    public function getFile()
    {
        return $this-&gt;file;
    }


}
</code></pre>

<p>My Media NewAction Controller:</p>

<pre><code>/**
     * Creates a new Media entity.
     *
     * @Route("/new", name="media_new")
     * @Method({"GET", "POST"})
     */
    public function newAction(Request $request)
    {
        $media = new Media();
        $form = $this-&gt;createForm('AdminBundle\Form\MediaType', $media);
        $form-&gt;handleRequest($request);

        if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {

                // $file stores the uploaded file
                /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
                $file = $media-&gt;getFile();

                // Generate a unique name for the file before saving it
                $fileName = md5(uniqid()).'.'.$file-&gt;guessExtension();

                // Move the file to the directory where media are stored
                $fileDir = $this-&gt;container-&gt;getParameter('kernel.root_dir').'/../web/uploads/';
                $file-&gt;move($fileDir, $fileName);

                // Update the 'media' property to store the file name
                // instead of its contents
                $media-&gt;setFile($fileName);



            $em = $this-&gt;getDoctrine()-&gt;getManager();
            $em-&gt;persist($media);
            $em-&gt;flush();

            return $this-&gt;redirectToRoute('media_show', array('id' =&gt; $media-&gt;getId()));
        }

        return $this-&gt;render('AdminBundle:media:new.html.twig', array(
            'medium' =&gt; $media,
            'form' =&gt; $form-&gt;createView(),
        ));
    }
</code></pre>

<p>My media FormType:</p>

<pre><code>&lt;?php

namespace AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;

class MediaType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            -&gt;add('libelle')
            -&gt;add('catmedia','entity',  array('class'=&gt;'AdminBundle:CatMedia',
                'property'=&gt;'libelle'))
            -&gt;add('file', FileType::class, array('label' =&gt; 'Image (Png or jpg file)'))
        ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver-&gt;setDefaults(array(
            'data_class' =&gt; 'AdminBundle\Entity\Media'
        ));
    }


}
</code></pre>

<p>and User Formtype using Media FormType:</p>

<pre><code>&lt;?php

namespace AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UtilisateurType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            -&gt;add('nom')
            -&gt;add('prenom')
            -&gt;add('societe')
            -&gt;add('mail')
            -&gt;add('tel')
            -&gt;add('password')
            -&gt;add('catutilisateur','entity',  array('class'=&gt;'AdminBundle:CatUtilisateur',
                'property'=&gt;'libelle'))
            -&gt;add('media', MediaType::class)



        ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver-&gt;setDefaults(array(
            'data_class' =&gt; 'AdminBundle\Entity\Utilisateur'
        ));
    }
}
</code></pre>

<p>As you can see, i have my move Function. But I do not have the directory uploads into web/, and in the database , I have this famous</p>

<blockquote>
<pre><code>+---------+----+--------------+----------------+
| Libelle | ID | Cat_Media_ID | file           |
+---------+----+--------------+----------------+
| test    |  1 |            1 | /tmp/phpY0oLd6 |
+---------+----+--------------+----------------+
</code></pre>
</blockquote>