mhunesi / yii2-storage
File Storage Abstraction for Yii2
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- league/flysystem: ~1.0
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-imagine: 2.3.*
Requires (Dev)
- league/flysystem-aws-s3-v3: ~1.0
- league/flysystem-azure: ~1.0
- league/flysystem-cached-adapter: ~1.0
- league/flysystem-gridfs: ~1.0
- league/flysystem-rackspace: ~1.0
- league/flysystem-replicate-adapter: ~1.0
- league/flysystem-sftp: ~1.0
- league/flysystem-webdav: ~1.0
- league/flysystem-ziparchive: ~1.0
- spatie/flysystem-dropbox: ~1.0
- yiisoft/yii2-queue: 2.3.*
Conflicts
- league/flysystem-aws-s3-v3: <1.0.26
This package is auto-updated.
Last update: 2025-02-26 16:05:44 UTC
README
File Storage Component for Yii2
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mhunesi/yii2-storage "*"
or add
"mhunesi/yii2-storage": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
'components' => [ //... 'storage' => [ 'class' => '\mhunesi\storage\Storage', 'defaultStorage' => 'local', 'queueFilters' => true, 'queueFiltersList' => ['tiny-crop', 'medium-thumbnail'], 'downloadValidationKey' => 'YII_STORAGE_KEY', 'downloadUrl' => '/site/download', 'storages' => [ 'local' => [ 'class' => '\mhunesi\storage\filesystem\LocalFilesystem', 'path' => '@app/web/uploads', 'cache' => 'cache', 'cacheKey' => 'filesystem_file', //'replica' => 'minio', 'replica' => [ 'class' => '\mhunesi\storage\filesystem\LocalFilesystem', 'path' => '@app/web/uploads2', 'cache' => 'cache', 'cacheKey' => 'filesystem_file_2', ] ], 'aws' => [ 'class' => 'mhunesi\storage\filesystem\AwsS3Filesystem', 'bucket' => 'bucket_name', 'key' => '_key', 'secret' => 'secret_key', 'region' => 'eu-central-1', // 'version' => 'latest', 'prefix' => 'wss', 'cache' => 'cache', 'cacheKey' => 'filesystem_aws', 'replica' => [ 'class' => '\mhunesi\storage\filesystem\LocalFilesystem', 'path' => '@app/web/uploads2', 'cache' => 'cache', 'cacheKey' => 'filesystem_file_2', ], ], 'minio' => [ 'class' => 'mhunesi\storage\filesystem\AwsS3Filesystem', 'bucket' => 'bucket_name', 'key' => '_key', 'secret' => 'scret_key', 'region' => 'eu-central-1', // 'version' => 'latest', // 'baseUrl' => 'your-base-url', 'prefix' => 'subfolder', // 'options' => [], 'endpoint' => 'http://127.0.0.1:49160', 'cache' => 'cache', 'cacheKey' => 'filesystem_minio' ], 'ftp' => [ 'class' => 'mhunesi\storage\filesystem\FtpFilesystem', 'host' => '192.168.1.1', 'port' => 21, 'username' => 'ftp_username', 'password' => 'ftp_password', 'cache' => 'cache', 'cacheKey' => 'filesystem_ftp1', // 'ssl' => true, // 'timeout' => 60, 'root' => '/rootPath', 'publicUrl' => 'http://ftp_url/', // 'permPrivate' => 0700, // 'permPublic' => 0744, // 'passive' => false, // 'transferMode' => FTP_TEXT, 'replica' => 'local', ], ] ] //... ],
'controllerMap' => [ 'migrate' => [ //.. 'migrationNamespaces' => [ //.. ], 'migrationPath' => [ //.. '@mhunesi/storage/migrations' ] ] ],
Upload & Download Action
/** * {@inheritdoc} */ public function actions() { return [ 'download' => [ 'class' => 'mhunesi\storage\actions\DownloadAction', ], 'upload' => [ 'class' => 'mhunesi\storage\actions\FileUploadAction', 'use_strict' => true, 'path' => 'folder/folder', 'folder' => 1, 'hidden' => true, 'visibility' => AdapterInterface::VISIBILITY_PUBLIC ], ]; }
URL Rules
'rules' => [ 'download/<token:[a-zA-Z0-9_\-\+\%\/=]*>/<filename:[a-zA-Z0-9_\-\+\%\.\ \/=]*>' => 'site/download' ]