kak/storage file upload/resize/crop file move storage

extensionstorage

Storage and Upload file for Yii2

file upload/resize

Any contributions are welcome Preview

PreviewUpload.png

Crop Preview (large image)

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist kak/storage "*"

or add

"kak/storage": "*"

to the require section of your composer.json file and run command composer update

Usage

PLS set config params Yii::$app->params

/** @docs https://console.aws.amazon.com/iam/home Generation access key and secret */
$amazon_config = [
    'key' => '', 
    'secret' => '',
    'bucket' => 'my',
    'level'  => 2,
    'type'   => 'amazon',
    'region' => 'us-east-1',
]

//...
'storage' => [
    'storages' => [
         // use amazon config
        'photo'  => $amazon_config,
        'custom_name' => [],
        // local server save files
        'tmp'  => [       
            'level' => 0,
        ],
    ],
],

Example use controller this uploading

    public function actions()
    {
         return [
             'upload' => [
                 'class' => UploadAction::className(),
                 'form_name' => 'kak\storage\models\UploadForm',
                 'storage'  => 'tmp',   // save image default tmp storage
                 'resize_image' => [    // list formats
                     'preview'   => [1024,1024, UploadAction::IMAGE_RESIZE, 'options' => [] ],
                     'thumbnail' => [120,120, UploadAction::IMAGE_THUMB],
                     '350'       => [350,280, UploadAction::IMAGE_RESIZE],
                 ]
             ],
         ];
     }

resize_image.options

  • animate if true then save image gif animated else first moveclip
  • quality 10 - 100

Save model then controller


    /**
    * @param $id int edit post
    * @return string
    */         
    public function actionUpdate($id)
    {
        $model = $this->findPostById($id);
        $uploadForm = new \kak\storage\models\UploadForm(['meta_name' => 'image_base']);
        $uploadForm->meta = $postModel->images_json;

        if($this->savePostForm($model, $uploadForm)) {
            return $this->redirect(['/dashboard/post/update','id' => $postModel->id]);
        }
        return $this->render('form',compact(
            'model', 'uploadForm'
        ));
    }

    /**
     * @param $model Post
     * @param $uploadForm \kak\storage\models\UploadForm
     * @return bool
     */
    protected function savePostForm(&$model,&$uploadForm)
    {
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {

            $result = $uploadForm->saveToStorage('tmp','images',[]);
            $model->images_json = Json::encode($result);

            return $model->save();
        }

        return false;
    }

Once the extension is installed, simply use it in your code by:

<div>
    <?=\kak\storage\Upload::widget([
        'model' => $uploadFormModel,
        'url' => ['/dashboard/default/upload', 'resize_type' => 'thumbnail,350']    
    ]); ?>
</div>
<hr>

if arg name resize_type in GET only these types will be saved resize images

usage pjax

register assets the main layouts

StorageAsset::register($view);

pjax event add code

    $(document).on('pjax:end','.pjax-wrapper',function(e){
        //init old gui
        $('.kak-storage-upload').kakStorageUpload({});
    });

roadmap

2018: Q1 add storage google cloud, change guzzle http to yii2-http-client, change aws-sdk-php Q2 create new uploader widget + tests

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



0.1.4 is the latest of 4 releases



BSD-3-Clause license
Stats
6 github stars & 3 github forks
3 downloads in the last day
9 downloads in the last 30 days
1288 total downloads