xiranst/media-bundle

Help your application to upload file easier.

dev-master / 1.x-dev 2017-04-12 15:11 UTC

This package is not auto-updated.

Last update: 2024-04-19 17:41:51 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 }}