razonyang / yii2-uploader
Yii2 Uploader
Installs: 3 989
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 0
Open Issues: 1
Type:yii2-extension
Requires
- php: ^7.1
- creocoder/yii2-flysystem: ^0.9.3
- yiisoft/yii2: ~2.0.13
Requires (Dev)
- codeception/codeception: ^3.0
- codeception/verify: ^1.1
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-10-29 05:59:53 UTC
README
Supports multiple filesystems:
- Yii2 Flysystem - Local, FTP, AWS S3, Azure filesystem etc.
- Aliyun OSS Flysystem
Installation
composer require razonyang/yii2-uploader
Usage
Configuration:
return [ 'components' => [ 'filesystem' => [ 'class' => \creocoder\flysystem\LocalFilesystem::class, 'path' => '@webroot/resources', ], 'uploader' => [ 'class' => \RazonYang\Yii2\Uploader\Uploader::class, 'host' => 'http://localhost/resources', // the hostname relative to your uploaded files 'filesystem' => 'filesystem', ], ], ];
And then defines a form, UploadForm
class UploadForm extends \yii\base\Model { use \RazonYang\Yii2\Uploader\UploadModelTrait; public function handle() { if (!$this->validate()) { // handles error throw new \Exception('invalid file'); } $url = $this->upload(); return [ 'url' => $url, // ... other information ]; } } class UploadController extends \yii\web\Controller { public function actionUpload() { $form = new UploadForm([ 'file' => \yii\web\UploadedFile::getInstanceByName('file') ]); return $form->handle(); } }