title: how to get the path of a file upload and save in db using symfony2
body: <p>I have created a file uploads page. In my controller I want to get the uploaded path of the view and add it in the database for a particular id. For that I want the path of the file ans send it to the repository. The problem when I am using in my controller </p>
  
  <pre><code>if ($request-&gt;getMethod() == 'POST')
  
        { 
                  $form-&gt;bind($request);
  
          $file = $form["file"]-&gt;getData();
  
                  /* here it is giving the path like /tmp/phpkR4kgD */
                  $em = $this-&gt;getDoctrine()-&gt;getManager();
                  $user-&gt;upload();
              }
  this is my entity
  
  /**
       * Sets file.
       *
       * @param UploadedFile $file
  
       */
  
      public function setFile(UploadedFile $file = null)
      {
          $this-&gt;file = $file;
      }
      public function upload()
      {
      if (null === $this-&gt;file) 
      {
              return;
          }
      $this-&gt;file-&gt;move($this-&gt;getUploadRootDir(), $this-&gt;file-&gt;getClientOriginalName());
      $this-&gt;path = $this-&gt;file-&gt;getClientOriginalName();
      $this-&gt;file = null;
      }
      /**
       * Get file.
       *
       * @return UploadedFile
       */
      public function getFile()
      {
          return $this-&gt;file;
      }
  
      public function getAbsolutePath()
      {
          return null === $this-&gt;path
              ? null
              : $this-&gt;getUploadRootDir() . DIRECTORY_SEPARATOR . $this-&gt;path;
      }
  
      public function getWebPath()
      {
          return null === $this-&gt;path
              ? null
              : $this-&gt;getUploadDir() . DIRECTORY_SEPARATOR . $this-&gt;path;
      }
  
      protected function getUploadRootDir()
      {
          return __DIR__ . '/../../../../web/'. $this-&gt;getUploadDir();
      }
  
      protected function getUploadDir()
      {
          return 'uploads/';
      }
  </code></pre>
  
  <p>I have created my uploads folder in web folder of symfony</p>