dev-master
9999999-devSymfony FileBundle
GPL-3.0+
The Requires
- php >=5.3.2
- symfony/framework-bundle >=3.0
- twig/twig *
- doctrine/doctrine-bundle *
- stof/doctrine-extensions-bundle ^1.2
- liip/imagine-bundle ^1.8
by florianmarical
Symfony FileBundle
Attention the template use Gedmo Uploadable !, (*1)
Composer.json, (*2)
"require": { ..., "paradise/file-bundle": "dev-master" },
config.yml, (*3)
twig: form_themes: - 'FileBundle:Form:fields.html.twig'
In an entity, (*4)
/** * @var File * * @ORM\OneToOne(targetEntity="Paradise\FileBundle\Entity\File", cascade={"persist", "remove"}) @ORM\JoinColumn(name="favicon") * @Assert\File( * maxSize = "2M", * mimeTypes = {"image/jpeg", "image/gif", "image/png"}, * mimeTypesMessage = "The selected file is not a valid file", * notFoundMessage = "The file was not found on the disk", * uploadErrorMessage = "Error in upload file" * ) */ private $favicon;
In formType, (*5)
$builder->add('favicon', FileUploadType::class, array('attr' => array('placeholder' => 'Favicon'), 'required' => false, 'path' => true));
If path is true, the picture appears in the render, (*6)
In a controller for the upload. Attention at the parameter. he is in parameter.yml., (*7)
example: parameters: file: directory: 'uploads/directory', (*8)
$path = $this->getParameter('file')['site_directory'] . $site->getId(); $this->get('ServiceFile')->uploadFile($site->getFavicon(), $path);
Symfony FileBundle
GPL-3.0+