2017 © Pedro PelΓ‘ez
 

yii2-extension yii2-filemanager

Yii2 filemanager

image

d1soft/yii2-filemanager

Yii2 filemanager

  • Monday, July 2, 2018
  • by d1soft
  • Repository
  • 0 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 85 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Yii2 file manager

This module provide interface to collect and access all mediafiles in one place. Inspired by WordPress file manager., (*1)

Features

  • Integrated with TinyMCE editor.
  • Automatically create actually directory for uploaded files like "2014/12".
  • Automatically create thumbs for uploaded images
  • Unlimited number of sets of miniatures
  • All media files are stored in a database that allows you to attach to your object does not link to the image, and the id of the media file. This provides greater flexibility since in the future will be easy to change the size of thumbnails.
  • If your change thumbs sizes, your may resize all existing thumbs in settings.

Screenshots

, (*2)

, (*3)

, (*4)

, (*5)

, (*6)

, (*7)

, (*8)

Installation

The preferred way to install this extension is through composer., (*9)

Either run, (*10)

php composer.phar require --prefer-dist d1soft/yii2-filemanager "*"

or add, (*11)

"d1soft/yii2-filemanager": "*"

to the require section of your composer.json file., (*12)

Apply migration, (*13)

yii migrate --migrationPath=vendor/d1soft/yii2-filemanager/migrations

Configuration:, (*14)

'modules' => [
    'filemanager' => [
        'class' => 'd1soft\filemanager\Module',
        // Upload routes
        'routes' => [
            // Base absolute path to web directory
            'baseUrl' => '',
            // Base web directory url
            'basePath' => '@frontend/web',
            // Path for uploaded files in web directory
            'uploadPath' => 'uploads',
        ],
        // Thumbnails info
        'thumbs' => [
            'small' => [
                'name' => 'МСлкий',
                'size' => [100, 100],
            ],
            'medium' => [
                'name' => 'Π‘Ρ€Π΅Π΄Π½ΠΈΠΉ',
                'size' => [300, 200],
            ],
            'large' => [
                'name' => 'Π‘ΠΎΠ»ΡŒΡˆΠΎΠΉ',
                'size' => [500, 400],
            ],
        ],
    ],
],

By default, thumbnails are resized in "outbound" or "fill" mode. To switch to "inset" or "fit" mode, use mode parameter and provide. Possible values: outbound (\Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND) or inset (\Imagine\Image\ImageInterface::THUMBNAIL_INSET):, (*15)

'thumbs' => [
    'small' => [
        'name' => 'МСлкий',
        'size' => [100, 100],
    ],
    'medium' => [
        'name' => 'Π‘Ρ€Π΅Π΄Π½ΠΈΠΉ',
        'size' => [300, 200],
    ],
    'large' => [
        'name' => 'Π‘ΠΎΠ»ΡŒΡˆΠΎΠΉ',
        'size' => [500, 400],
        'mode' => \Imagine\Image\ImageInterface::THUMBNAIL_INSET
    ],
],

Usage

Simple standalone field:, (*16)

use d1soft\filemanager\widgets\FileInput;

echo $form->field($model, 'original_thumbnail')->widget(FileInput::className(), [
    'buttonTag' => 'button',
    'buttonName' => 'Browse',
    'buttonOptions' => ['class' => 'btn btn-default'],
    'options' => ['class' => 'form-control'],
    // Widget template
    'template' => '

{input}{button}
', // Optional, if set, only this image can be selected by user 'thumb' => 'original', // Optional, if set, in container will be inserted selected image 'imageContainer' => '.img', // Default to FileInput::DATA_URL. This data will be inserted in input field 'pasteData' => FileInput::DATA_URL, // JavaScript function, which will be called before insert file data to input. // Argument data contains file data. // data example: [alt: "Π’Π΅Π΄ΡŒΠΌΠ° с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"] 'callbackBeforeInsert' => 'function(e, data) { console.log( data ); }', ]); echo FileInput::widget([ 'name' => 'mediafile', 'buttonTag' => 'button', 'buttonName' => 'Browse', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['class' => 'form-control'], // Widget template 'template' => '
{input}{button}
', // Optional, if set, only this image can be selected by user 'thumb' => 'original', // Optional, if set, in container will be inserted selected image 'imageContainer' => '.img', // Default to FileInput::DATA_IDL. This data will be inserted in input field 'pasteData' => FileInput::DATA_ID, // JavaScript function, which will be called before insert file data to input. // Argument data contains file data. // data example: [alt: "Π’Π΅Π΄ΡŒΠΌΠ° с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"] 'callbackBeforeInsert' => 'function(e, data) { console.log( data ); }', ]);

With TinyMCE:, (*17)

use d1soft\filemanager\widgets\TinyMCE;

= $form->field($model, 'content')->widget(TinyMCE::className(), [
    'clientOptions' => [
           'language' => 'ru',
        'menubar' => false,
        'height' => 500,
        'image_dimensions' => false,
        'plugins' => [
            'advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code contextmenu table',
        ],
        'toolbar' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code',
    ],
]); ?>

In model you must set mediafile behavior like this example:, (*18)

use d1soft\filemanager\behaviors\MediafileBehavior;

public function behaviors()
{
    return [
        'mediafile' => [
            'class' => MediafileBehavior::className(),
            'name' => 'post',
            'attributes' => [
                'thumbnail',
            ],
        ]
    ];
}

Than, you may get mediafile from your owner model. See example:, (*19)

use d1soft\filemanager\models\Mediafile;

$model = Post::findOne(1);
$mediafile = Mediafile::loadOneByOwner('post', $model->id, 'thumbnail');

// Ok, we have mediafile object! Let's do something with him:
// return url for small thumbnail, for example: '/uploads/2014/12/flying-cats.jpg'
echo $mediafile->getThumbUrl('small');
// return image tag for thumbnail, for example: '<img src="/uploads/2014/12/flying-cats.jpg" alt="Π›Π΅Ρ‚Π°ΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΡ‚Ρ‹">'
echo $mediafile->getThumbImage('small'); // return url for small thumbnail

The Versions

02/07 2018

dev-master

9999999-dev

Yii2 filemanager

  Sources   Download

MIT

The Requires

 

by PendalF
by Avatar d1soft

02/07 2018
02/07 2018

dev-fixes

dev-fixes

Yii2 filemanager

  Sources   Download

MIT

The Requires

 

by PendalF
by Avatar d1soft