2017 © Pedro Peláez
 

library yii2-media

Media Manipulation and storage control (limitation) in Yii2

image

mhndev/yii2-media

Media Manipulation and storage control (limitation) in Yii2

  • Tuesday, November 1, 2016
  • by majidphpdeveloper
  • Repository
  • 3 Watchers
  • 2 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Yii2 Media Manipulation Module

media manipulation implementation in Yii2, (*1)

Installation

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

Either run, (*3)

composer require --prefer-dist mhndev/yii2-media "0.*"

or add, (*4)

"mhndev/yii2-media": "0.*"

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

Introduction

This package helps you manipulate any kind of media (image , video, text, pdf, ...) for any kind of entity you like. for example consider you have a Post Entity , first of all you should use EntityTrait in your model just like following :, (*6)

namespace app\models;

use mhndev\yii2Media\Interfaces\iEntity;
use mhndev\yii2Media\Traits\EntityTrait;
use yii\db\ActiveRecord;

/**
 * Class Post
 * @package app\models
 */
class Post extends ActiveRecord implements iEntity
{

    use EntityTrait;

    /**
     * @return string
     */
    public static function tableName()
    {
        return 'posts';
    }



}

this package also helps you upload media and specify max upload size for any kind of media and mime types and also you can specify this package log if memory directory size which you upload file is less than x MB., (*7)

create a config file called media like follow :, (*8)

<?php
return [
    'mediaClass' => \mhndev\yii2Media\Models\Media::class,


    'userClass' => \app\modules\user\models\User::class,

    'formats' => [


        'image'=>[
            'avatar'=>[
                'storagePath'=> Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'avatar',
                'uploadSizeLimit' => 2,
            ],

            'post-cover' => [
                'storagePath' => Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'post/cover',
                'uploadSizeLimit' => 3
            ],


            'cover' => [
                'storagePath' => Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'cover',
                'uploadSizeLimit' => 3
            ],

            'post-list-view' => [
                'storagePath' => Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'post/list',
                'uploadSizeLimit' => 4
            ]
        ],

        'audio'=>[
            'music'=>[
                'storagePath'=> Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'music',
                'uploadSizeLimit' => 10

            ],
            'english-learning'=>[
                'storagePath'=> Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'english-learning',
                'uploadSizeLimit' => 4

            ]
        ],

        'video'=>[
            'storagePath'=> Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'video',
            'uploadSizeLimit' => 10
        ],


        'text'=>[

            'document'=>[
                'storagePath'=> Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'text',
                'uploadSizeLimit' => 1
            ]
        ],

    ],


    'min_storage' => 100


];


This Package comes with a Media Controller which has following actions.

actionDefaultMedia

this action takes an media Id and set it as default media., (*9)

    /**
     * @param string $media_id
     * @return mixed
     */
    public static function markMediaAsDefaultByMediaId($media_id)
    {
        $mediaClass = self::mediaClass();

        /** @var iMedia $media */
        $media = $mediaClass::findOne($media_id);

        return $media->markAsDefault();
    }
actionUploadAndAttachMedia

this action takes multiple file as input file upload and attach to specified entity., (*10)

    /**
     * @return array|string
     */
    public function actionUploadAndAttachMedia()
    {
        $data = Yii::$app->request->post();
        $model = $data['entity']::findOne($data['entity_id']);

        return ['records'=>Media::storeAndAttach('media', $data['type'], $model)];
    }

this is action code and you can see exactly what it does., (*11)

The Versions

01/11 2016

dev-master

9999999-dev

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

01/11 2016

dev-develop

dev-develop

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

06/10 2016

0.0.5

0.0.5.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

21/09 2016

0.0.4

0.0.4.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

21/09 2016

0.0.3

0.0.3.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

21/09 2016

0.0.2

0.0.2.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

20/09 2016

0.0.1

0.0.1.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation

20/09 2016

0.0.0

0.0.0.0

Media Manipulation and storage control (limitation) in Yii2

  Sources   Download

MIT

The Requires

 

yii2 upload image media manipulation