PHP code example of cyneek / yii2-upload-behavior
1. Go to this page and download the library: Download cyneek/yii2-upload-behavior library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cyneek / yii2-upload-behavior example snippets yii migrate --migrationPath=@vendor/cyneek/yii2-upload-behavior/migrations
[
'thumbName' => [
['action' => 'crop', 'width' => 200, 'height' => 200, 'quality' => 90],
...
]
]
[
['action' => 'crop', 'width' => 200, 'height' => 200, 'quality' => 90]
]
public $file;
public $avatar;
function behaviors()
{
return [
[
'class' => UploadBehavior::className(),
'attribute' => 'file',
'scenarios' => ['default'],
'fileActionOnSave' => 'delete'
],
[
'class' => UploadImageBehavior::className(),
'attribute' => 'avatar',
'scnearios' => ['default'],
'fileActionOnSave' => 'delete'
'imageActions' => [['action' => 'thumbnail', 'width' => '900', 'height' => '400']]
],
];
}
public function rules()
{
return [
...
[['file', 'avatar'], 'file', 'on' => ['insert', 'update', 'default']],
['file', '
<?= $form->field($model, 'file')->fileInput()
$object = MethodClass::find()->where(['id' => 1])->one();
$file = $object->linkedFile('file');
$object = MethodClass::find()->where(['id' => 1])->one();
$fileList = $object->linkedFiles('file');
$object = MethodClass::find()->where(['id' => 1])->one();
$file = $object->linkedFile('file');
$object->deleteFiles('file', $file);
$object = MethodClass::find()->where(['id' => 1])->one();
$object->deleteFiles('file');
$object = MethodClass::find()->where(['id' => 1])->one();
$file = $object->linkedFile('file');
$thumbnail = $file->getChild('thumb');
$object = MethodClass::find()->where(['id' => 1])->one();
$file = $object->linkedFile('file');
$thumbnailList = $file->getChildren();