xiranst / media-bundle
Help your application to upload file easier.
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4.0
- symfony/symfony: >=3.0
This package is not auto-updated.
Last update: 2024-11-01 20:03:00 UTC
README
Help your application to upload file easier.
1, Installation with composer
$ composer require xiranst/media-bundle:dev-master
2, Enable in AppKernel.php
// app/AppKernel.php <?php // ... public function registerBundles() { $bundles = array( // ... new Xiranst\Bundle\MediaBundle\XiranstMediaBundle(), ); }
3, Usage in Form Type
<?php // src/Xiranst/Bundle/DemoBundle/Form/YourFormType.php namespace Xiranst\Bundle\DemoBundle\Form; use Xiranst\Bundle\MediaBundle\Form\ThumbnailType; class YourFormType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder->add('thumbnail', ThumbnailType::class); // ... } // ... }
4, Options
a, Configure the upload directory in config.yml
Default directory is:
%kernel.root_dir%/../web/uploads/media
Please make the permission of web/uploads/media directory is 0777;
If you need to change this path, please add this configuration in config.yml
// app/config/config.yml xiranst_media: upload_directory: '%kernel.root_dir%/../your-directory/'
b, if the file has uploaded and you want to display it in the form template, you can use this code:
{{ form.vars.data.thumbnail }}