src/Flowcode/UserBundle/Service/UserService.php
public function uploadImage(User $entity)
    {

        /* the file property can be empty if the field is not required */
        if (null === $entity->getFile()) {
            return $entity;
        }

        $uploadBaseDir = $this->container->getParameter("user_avatar_basedir");
        $uploadDir = $this->container->getParameter("user_avatar_dir");

        /* set the path property to the filename where you've saved the file */
        $filename = $entity->getFile()->getClientOriginalName();
        $extension = $entity->getFile()->getClientOriginalExtension();

        $imageName = md5($filename . time()) . '.' . $extension;

        $entity->setAvatar($uploadDir . $imageName);
        $entity->getFile()->move($uploadBaseDir . $uploadDir, $imageName);

        $entity->setFile(null);

        return $entity;
    }
public function uploadImage(User $entity)
    {

        /* the file property can be empty if the field is not required */
        if (null === $entity->getFile()) {
            return $entity;
        }

        $uploadBaseDir = $this->container->getParameter("user_avatar_basedir");
        $uploadDir = $this->container->getParameter("user_avatar_dir");

        /* set the path property to the filename where you've saved the file */
        $filename = $entity->getFile()->getClientOriginalName();
        $extension = $entity->getFile()->getClientOriginalExtension();

        $imageName = md5($filename . time()) . '.' . $extension;

        $entity->setAvatar($uploadDir . $imageName);
        $entity->getFile()->move($uploadBaseDir . $uploadDir, $imageName);

        $entity->setFile(null);

        return $entity;
    }
public function uploadImage ( User $ entity ) { /* the file property can be empty if the field is not required */ if ( null === $ entity -> getFile ( ) ) { return $ entity ; } $ uploadBaseDir = $ this -> container -> getParameter ( "user_avatar_basedir" ) ; $ uploadDir = $ this -> container -> getParameter ( "user_avatar_dir" ) ; /* set the path property to the filename where you've saved the file */ $ filename = $ entity -> getFile ( ) -> getClientOriginalName ( ) ; $ extension = $ entity -> getFile ( ) -> getClientOriginalExtension ( ) ; $ imageName = md5 ( $ filename . time ( ) ) . '.' . $ extension ; $ entity -> setAvatar ( $ uploadDir . $ imageName ) ; $ entity -> getFile ( ) -> move ( $ uploadBaseDir . $ uploadDir , $ imageName ) ; $ entity -> setFile ( null ) ; return $ entity ; }
Upload user image.

@param User $entity
@return User
Upload user image .