Skip to content

Instantly share code, notes, and snippets.

@jmather
Created October 30, 2012 02:18
Show Gist options
  • Select an option

  • Save jmather/3977936 to your computer and use it in GitHub Desktop.

Select an option

Save jmather/3977936 to your computer and use it in GitHub Desktop.
File Upload Setup
vich_uploader:
db_driver: orm
# gaufrette: true
# storage: vich_uploader.storage.gaufrette
mappings:
# profile_image:
# uri_prefix: /images/profiles
# upload_destination: profile_image_fs
profile_image:
uri_prefix: /images/profiles
upload_destination: %kernel.root_dir%/../web/images/profiles
<?php
/**
* This file is part of the <name> project.
*
* (c) <yourname> <youremail>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This file has been generated by the Sonata EasyExtends bundle ( http://sonata-project.org/easy-extends )
*
* References :
* working with object : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
*
* @author <yourname> <youremail>
* @Vich\Uploadable
*/
class User extends BaseUser
{
protected $organizations;
/**
* @Assert\File(
* maxSize="2M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="profile_image", fileNameProperty="profile_image_name")
*
* @var File $image
*/
protected $profile_image;
/**
* @var string $profile_image_name
*/
protected $profile_image_name;
public function __construct()
{
parent::__construct();
$this->organizations = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var integer $id
*/
protected $id;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
public function addOrganization($organization)
{
$this->organizations[] = $organization;
}
public function setOrganizations($organizations)
{
$this->organizations = $organizations;
}
public function getOrganizations()
{
return $this->organizations;
}
public function setProfileImage($profile_image)
{
$this->profile_image = $profile_image;
}
public function getProfileImage()
{
return $this->profile_image;
}
/**
* @param string $profile_image_name
*/
public function setProfileImageName($profile_image_name)
{
$this->profile_image_name = $profile_image_name;
}
/**
* @return string
*/
public function getProfileImageName()
{
return $this->profile_image_name;
}
}
@fkrauthan
Copy link
Copy Markdown

Why don't you use the Assert\Image validation constraint?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment