PHP code example of slexx / yii2-file-kit
1. Go to this page and download the library: Download slexx/yii2-file-kit 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/ */
slexx / yii2-file-kit example snippets
public function behaviors()
{
return [
'file' => [
'class' => 'trntv\filekit\behaviors\UploadBehavior',
'uploadAttribute' => 'file',
'resultAttribute' => 'path',
'fileCategory' => 'products',
'fileRepository' => 'uploads',
'fileProcessing'=>function($file, $uploadAction){
// resize etc
}
],
];
}
echo \trntv\filekit\widget\Upload::widget([
'model'=>$model,
'attribute'=>'files',
'url'=>['upload'],
'sortable'=>true,
'fileuploadOptions'=>[
'maxFileSize'=>10000000, // 10 MiB
'maxNumberOfFiles'=>3
]
])
public function actions(){
return [
'upload'=>[
'class'=>'trntv\filekit\actions\UploadAction',
'responseUrlParam'=>'file-url',
'fileProcessing'=>function($file, $uploadAction){
// do something (resize, add watermark etc)
}
]
];
}
$path = new \trntv\filekit\base\Path(['path'=>'/var/www/images/product.jpg'])
echo $path->filename; // product.jpg
$path->filename = 'service.jpg';
echo $path; // /var/www/images/service.jpg
$path->addFilenamePrefix('_thumb');
echo $path->filename; // service_thumb.jpg
echo $path; // /var/www/images/service_thumb.jpg
$url = new \trntv\filekit\base\Url(['url'=>'http://example.com/1/test.php'])
echo $url->host; // example.com
echo $url->path->filename; // test.php;
$url->port = 88;
$url->path->filename = 'product.jpg';
echo $url; // http://example.com:88/1/product.jpg
$url->path->addFilenamePrefix('_thumb');
echo $url; // http://example.com:88/1/product_thumb.jpg