Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/razonyang/yii2-uploader
Yii2 File Uploader
https://github.com/razonyang/yii2-uploader
Last synced: 20 days ago
JSON representation
Yii2 File Uploader
- Host: GitHub
- URL: https://github.com/razonyang/yii2-uploader
- Owner: razonyang
- License: bsd-3-clause
- Created: 2019-08-07T10:35:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-30T10:43:27.000Z (about 5 years ago)
- Last Synced: 2024-05-22T13:32:51.320Z (6 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Yii2 Uploader
=============[![Build Status](https://travis-ci.org/razonyang/yii2-uploader.svg?branch=master)](https://travis-ci.org/razonyang/yii2-uploader)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/razonyang/yii2-uploader/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/razonyang/yii2-uploader/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/razonyang/yii2-uploader/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/razonyang/yii2-uploader/?branch=master)
[![Latest Stable Version](https://img.shields.io/packagist/v/razonyang/yii2-uploader.svg)](https://packagist.org/packages/razonyang/yii2-uploader)
[![Total Downloads](https://img.shields.io/packagist/dt/razonyang/yii2-uploader.svg)](https://packagist.org/packages/razonyang/yii2-uploader)
[![LICENSE](https://img.shields.io/github/license/razonyang/yii2-uploader)](LICENSE)Supports multiple filesystems:
- [Yii2 Flysystem](https://github.com/creocoder/yii2-flysystem) - Local, FTP, AWS S3, Azure filesystem etc.
- [Aliyun OSS Flysystem](https://github.com/razonyang/yii2-flysystem-aliyun-oss)Installation
------------```
composer require razonyang/yii2-uploader
```Usage
-----Configuration:
```php
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`
```php
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();
}
}
```