Help your application to upload file easier., (*1)
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(),
);
}
<?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, (*2)
Default directory is:, (*3)
%kernel.root_dir%/../web/uploads/media
Please make the permission of web/uploads/media directory is 0777;, (*4)
If you need to change this path, please add this configuration in config.yml, (*5)
// 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:, (*6)
{{ form.vars.data.thumbnail }}