kak / storage
file upload/resize/crop file move storage
Installs: 1 343
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 2
Open Issues: 1
Type:yii2-extension
Requires
- php: >=5.4.0
- aws/aws-sdk-php: 3.*
- bower-asset/blueimp-file-upload: 9.10.5
- bower-asset/cropper: 0.10.1
- yiisoft/yii2: *
- yiisoft/yii2-imagine: *
- yiisoft/yii2-jui: *
This package is auto-updated.
Last update: 2024-10-17 22:47:20 UTC
README
file upload/resize
Any contributions are welcome Preview
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