I'm trying to upload a file using my own form with symfony2.
I get no errors, and the name of the file is correctly addeded on database, but the file is not uploaded.

here is my **routing.yml** :

```
upload_homepage:
    pattern:  /upload
    defaults: { _controller: UploadBundle:Default:index }
upload:
    pattern:  /upload/file
    defaults: { _controller: UploadBundle:Default:upload }

```

**twig:**

```
<form enctype="multipart/form-data" action="{{ path('upload') }}" method="POST">
    <input type="file" name="file">
    <input type="submit">
</form>

```

**My controller :**

```
<?php

namespace Upload\UploadBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

use Upload\UploadBundle\Entity\Document;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('UploadBundle:Default:index.html.twig');
    }

    public function uploadAction(Request $request)
    {

        $em = $this->getDoctrine()->getManager();
        $document = new Document();
        $document->setChemain($request->files->get('file')->getClientOriginalName());
        //$document->upload();
        // print_r($request->files->get('file')->getClientOriginalName());
        // die();
        $em->persist($document);
        $em->flush();
        return new Response("Ok");
    }
}

```

The Entity:

```
<?php

namespace Upload\UploadBundle\Entity;

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

/**
 * Document
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Upload\UploadBundle\Entity\DocumentRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Document
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="chemain", type="string", length=255)
     */
    private $chemain;

    /**
     * @Assert\File(maxSize="6000000")
     * mimeTypes = {"image/jpg", "image/gif", "image/png", "image/tiff"},
     * maxSizeMessage = "The maxmimum allowed file size is 5MB.",
     * mimeTypesMessage = "Only the filetypes image are allowed."
     */
    public $file;
    /**
     * Get id
     *
     * @return integer 
     */

    // propriété utilisé temporairement pour la suppression
    private $filenameForRemove;

    public function getId()
    {
        return $this->id;
    }

    /**
     * Set chemain
     *
     * @param string $chemain
     * @return Document
     */
    public function setChemain($chemain)
    {
        $this->chemain = $chemain;

        return $this;
    }

    /**
     * Get chemain
     *
     * @return string 
     */
    public function getChemain()
    {
        return $this->chemain;
    }

    public function getWebPath()
    {
        return null === $this->chemain ? null : $this->getUploadDir().'/'.$this->chemain;
    }

    protected function getUploadRootDir()
    {

        return __DIR__.'/../../../../web/'.$this->getUploadDir();
    }

    protected function getUploadDir()
    {

        return 'uploads';
    }

/**
     * @ORM\PrePersist()
     * @ORM\PreUpdate()
     */
    public function preUpload()
    {
        if (null !== $this->file) {
            $this->chemain = $this->file->guessExtension();
        }
    }

    /**
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
     */
    public function upload()
    {
        if (null === $this->file) {
            return;
        }

        try {
             $this->file->move($this->getUploadRootDir(), $this->id.'.'.$this->file->guessExtension());
             unset($this->file);
        } catch (FileException $e) {
            return $e;
        }

    }

    /**
     * @ORM\PreRemove()
     */
    public function storeFilenameForRemove()
    {
        $this->filenameForRemove = $this->getAbsolutePath();
    }

    /**
     * @ORM\PostRemove()
     */
    public function removeUpload()
    {
        if ($this->filenameForRemove) {
            unlink($this->filenameForRemove);
        }
    }

    public function getAbsolutePath()
    {
        return null === $this->chemain ? null : $this->getUploadRootDir().'/'.$this->id.'.'.$this->chemain;
    }
}

```

Any idea ?