title: doctrine2 and Symfony2 upload file (mimeTypes for csv), get the right extension
body: <p>I am using the symfony upload method in order to import csv or exel files into my application.</p>
  
  <p>My problem is that symfony/doctrine don't recognize my csv file if I don't write this mimeTypes <code>"text/plain"</code>.</p>
  
  <p>Let me explain correctly. This is my entity code:</p>
  
  <pre><code>namespace ...
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  
  /**
   * Documents
   *
   * @ORM\Table(name="documents")
   * @ORM\Entity(repositoryClass="MySpace\MyBundle\Repository\DocumentsRepository")
   * @ORM\HasLifecycleCallbacks
   */
  class Documents
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
      /**
       * @var string
       *
       * @ORM\Column(name="doc_name", type="string", length=50, nullable=false)
       * @Assert\NotBlank
       */
      private $nomDocSuivis;
      /**
       * @var string
       *
       * @ORM\Column(name="doc_path", type="string", length=255, nullable=true)
       */
      private $path;
      /**
       * @var string $file
       * @Assert\File( maxSize = "100000000", mimeTypes= {"text/csv", "application/csv", "text/excel", "application/excel"}, mimeTypesMessage = "Please upload a valid CSV | exel file")
       */
      private $file;
  
      /*getters and setters*/
  }
  </code></pre>
  
  <p>of course I am using a simply controller method to persist and flush an entity, nothing's wrong here. But when I upload my csv files or exel files, I have the <code>mimeTypesMessage = "Please upload a valid CSV | exel file"</code>. That is to say, symfony does not recognize my csv files.</p>
  
  <p>Here's my controller code:</p>
  
  <pre><code>public function uploadAction()
      {
        $em=$this-&gt;getDoctrine()-&gt;getManager();
        $doc = new Documents;
  
        $form=$this-&gt;createForm(new DocumentsType(), $doc);
        $form-&gt;remove('path');
  
        if ($this-&gt;getRequest()-&gt;isMethod('POST')) {
          $form-&gt;handleRequest($this-&gt;getRequest());
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
  
              // An easy way to handle the file upload is to move it just before the entity is persisted and then set the path property accordingly
              // $docSuivi-&gt;upload();
              $doc = $form-&gt;get('file');
              $doc = $form-&gt;getData();
              $em-&gt;persist($doc);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('indexDocuments'));
          }
      }
  
       return $this-&gt;render('MySpaceMyBundle:Documents:uploadDocuments.html.twig', array('form' =&gt; $form-&gt;createView() ));
      }
  </code></pre>
  
  <p>And finally my Symfony Form Builder:</p>
  
  <pre><code>class DocumentsSuivisConsoType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('docName')
              -&gt;add('path')
              -&gt;add('file')
              -&gt;add('compteurs')
          ;
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'MySpace\MyBundle\Entity\Documents'
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'mySpace_myBundle_documents';
      }
  </code></pre>
  
  <p>But I if I add mimeTypes = "text/plain" like this:</p>
  
  <pre><code>    /**
       * @var string $file
       * @Assert\File( maxSize = "100000000", mimeTypes= {"text/plain", "text/csv", "application/csv", "text/excel", "application/excel"}, mimeTypesMessage = "Please upload a valid CSV | exel file")
       */
      private $file;
  </code></pre>
  
  <p>It works well, but register the extension as <code>.txt</code> instead of <code>.csv</code>. <strong>And of course my <code>.csv</code> file becomes a <code>.txt</code> file, that I do not want.</strong></p>
  
  <p>Where am I wrong?</p>