PHP code example of snewer / yii2-storage
1. Go to this page and download the library: Download snewer/yii2-storage 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/ */
snewer / yii2-storage example snippets
[
// ...
'components' => [
//...
'storage' => [
'class' => 'snewer\storage\StorageManager',
'buckets' => []
],
//...
],
// ...
]
snewer\storage\AbstractBucket
snewer\storage\drivers\FileSystemDriver
[
// ...
'components' => [
//...
'storage' => [
'class' => 'snewer\storage\StorageManager',
'buckets' => [
'images' => [
'class' => 'snewer\storage\drivers\FileSystemDriver',
'basePath' => '@frontend/web/uploads/images/',
'baseUrl' => '@web/uploads/images/',
'depth' => 4
],
'documents' => [
'class' => 'snewer\storage\drivers\FileSystemDriver',
'basePath' => '@frontend/web/uploads/documents/',
'baseUrl' => '@web/uploads/documents/',
'depth' => 4
],
// ...
]
],
//...
],
// ...
]
public static function upload($imageBinary)
{
$path = Yii::$app->storage->upload('images', $imageBinary, 'jpg');
$model = new self;
$model->path = $path;
$model->save();
return $model;
}
public function getUrl()
{
return Yii::$app->storage->getUrl('images', $this->path);
}
$image = app\models\Image::upload($imageBinary);
<img src="<?= $image->url
public static function upload($imageBinary)
{
$path = Yii::$app->storage->images->upload($imageBinary, 'jpg');
$model = new self;
$model->path = $path;
$model->save();
return $model;
}
public function getUrl()
{
return Yii::$app->storage->images->getUrl($this->path);
}
php composer.phar