title: File uploads in Symfony 2 using sonata-project
body: <p>I am trying to upload a image in Symfony 2 from the backend using sonata-project. Challenge that i'm facing right now is to get the image inserted into the database table and uploaded to the specified path. I have given my upload folder writeable permissions. I am not sure what i am missing but here are the steps that i have taken.</p>
  
  <pre><code>class HomeEnumerate
  {
  
  // ...
  protected function getUploadDir()
  {
      return 'uploads/houses';
  }
  
  protected function getUploadRootDir()
  {
      return __DIR__.'/../../../../web/'.$this-&gt;getUploadDir();
  }
  
  public function getWebPath()
  {
      return null === $this-&gt;house_picture ? null :   $this-&gt;getUploadDir().'/'.$this-&gt;house_picture;
  }
  
  public function getAbsolutePath()
  {
      return null === $this-&gt;house_picture ? null : $this-&gt;getUploadRootDir().'/'.$this-&gt;house_picture;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have edited my HomeEnumerate.orm.yml i have put in lifecycleCallbacks:</p>
  
  <pre><code>lifecycleCallbacks:
      prePersist: [ preUpload, setCreatedAtValue, setExpiresAtValue ]
      preUpdate: [ preUpload, setUpdatedAtValue ]
      postPersist: [ upload ]
      postUpdate: [ upload ]
      postRemove: [ removeUpload ]
  </code></pre>
  
  <p>After generate:entities I have edited my HomeEnumerate entity</p>
  
  <pre><code>class Job
  {
  // ...
  
  /**
   * @ORM\PrePersist
   */
  public function preUpload()
  {
       if (null !== $this-&gt;file) {
           $this-&gt;logo = uniqid().'.'.$this-&gt;file-&gt;guessExtension();
       }
  }
  
  /**
   * @ORM\PostPersist
   */
  public function upload()
  {
      if (null === $this-&gt;file) {
          return;
      }
  
      // If there is an error when moving the file, an exception will
      // be automatically thrown by move(). This will properly prevent
      // the entity from being persisted to the database on error
      $this-&gt;file-&gt;move($this-&gt;getUploadRootDir(), $this-&gt;logo);
  
      unset($this-&gt;file);
  }
  
  /**
   * @ORM\PostRemove
   */
  public function removeUpload()
  {
      if(file_exists($file)) {
          if ($file = $this-&gt;getAbsolutePath()) {
              unlink($file);
          }
      }    
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Can someone please help me uploading the files to the db and folder path.</p>