title: Call to a member function move() on a non-object
body: <p>I really wonder why I keep getting this error message whenever I try to upload a photo through a form in Symfony2:</p>
  
  <blockquote>
    <p>Error: Call to a member function move() on a non-object</p>
  </blockquote>
  
  <p>This is the code that exists in my entity file (<strong>Photo.php</strong>):</p>
  
  <pre><code>&lt;?php
  
  namespace Boutique\ProduitBundle\Entity;
  use Symfony\Component\Validator\Constraints as Assert;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Photo
   *
   * @ORM\Table()
   * @ORM\Entity
   */
  class Photo
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="image", type="string", length=255)
       */
      private $image;
  
      /**
       * 
       * @Assert\File(maxSize="5000k")
       */
      public $file;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set image
       *
       * @param string $image
       * @return Photo
       */
      public function setImage($image)
      {
          $this-&gt;image = $image;
  
          return $this;
      }
  
      /**
       * Get image
       *
       * @return string 
       */
      public function getImage()
      {
          return $this-&gt;image;
      }
  
      public function getWebPath()
      {
          return null === $this-&gt;image ? null : $this-&gt;getUploadDir().'/'.$this-&gt;image;
      }
       protected function getUploadRootDir()
      {
          // le chemin absolu du répertoire dans lequel sauvegarder les photos de profil
          //return __DIR__.'/../../../../web/groupe/'.$this-&gt;getUploadDir();
          return __DIR__.'/../../../../web/'.$this-&gt;getUploadDir(); 
      }
  
      protected function getUploadDir()
      {
          // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
          return 'uploads/pictures';
      }
       public function uploadPhotoPicture()
      {
          // Nous utilisons le nom de fichier original, donc il est dans la pratique 
          // nécessaire de le nettoyer pour éviter les problèmes de sécurité
  
          // move copie le fichier présent chez le client dans le répertoire indiqué.
          $this-&gt;file-&gt;move($this-&gt;getUploadRootDir(), $this-&gt;file-&gt;getClientOriginalName());
  
          // On sauvegarde le nom de fichier
          $this-&gt;image = $this-&gt;file-&gt;getClientOriginalName();
  
          // La propriété file ne servira plus
          $this-&gt;file = null;
      }
  }
  </code></pre>
  
  <p>The code in the controller file:</p>
  
  <pre><code>    &lt;?php
  
  namespace Boutique\ProduitBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Boutique\ProduitBundle\Entity\Photo;
  use Boutique\ProduitBundle\Form\PhotoType;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpFoundation\Response;
  
  class DefaultController extends Controller
  {    
     public function ajoutphotoAction(Request $request)
      {
          $photo = new Photo();
          $form = $this-&gt;createForm(new PhotoType(), $photo);
          if ($request-&gt;isMethod('POST')) {
              $form-&gt;handleRequest($request);
              if ($form-&gt;isValid()) {
                  $em = $this-&gt;getDoctrine()-&gt;getManager();
                  $photo-&gt;uploadPhotoPicture();
                  $em-&gt;persist($photo);
                  $em-&gt;flush();
                  $request-&gt;getSession()-&gt;getFlashBag()-&gt;add('success', 'Photo bien enregistrée.');
                  return new RedirectResponse($this-&gt;generateUrl('boutique_photo_ajout'));
              }
          }
          return $this-&gt;render('BoutiqueProduitBundle:Ajoutphoto:ajout.html.twig',
                  array('form' =&gt; $form-&gt;createView()));
      }
  }
  </code></pre>
  
  <p>I would like to know what wrong in my code is. Is there anything missing?</p>