PHPackages                             eluhr/yii2-fileflyupload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. eluhr/yii2-fileflyupload

ActiveLibrary[File &amp; Storage](/categories/file-storage)

eluhr/yii2-fileflyupload
========================

Filefly upload for yii2 models

1.0.1(4y ago)01.9kBSD-3-ClausePHP

Since Feb 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/eluhr/yii2-fileflyupload)[ Packagist](https://packagist.org/packages/eluhr/yii2-fileflyupload)[ RSS](/packages/eluhr-yii2-fileflyupload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 Filefly Upload
===================

[](#yii2-filefly-upload)

A little helper trait to easily upload files from a local filesystem to another filesystem

Installation
------------

[](#installation)

```
composer require eluhr/yii2-fileflyupload
```

Usage
-----

[](#usage)

Your config must configure the needed filesystems see [creocoder/yii2-flysystem](https://github.com/creocoder/yii2-flysystem#configuring)

Use the trait in your Model

```
 namespace example\namespace\models;

 use eluhr\fileflyupload\traits\FileflyUploadTrait;
 use yii\base\Model;
 use yii\helpers\FileHelper;

 class MyModel extends Model
 {
     use FileflyUploadTrait;

     public $file;

     public function getLocalFs(): string {
         return 'fsLocal';
     }

     public function getStorageFs(): string {
         return 'fsStorage';
     }

     public function rules(): array
     {
         $rules = parent::rules();
         $rules[] = [
             'file',
             'file',
             'skipOnEmpty' => false,
             'extensions' => 'pdf',
             'maxSize' => 3145728 // 3 MB
         ];
         return $rules;
     }

     public function upload(): bool
     {
         if ($this->validate()) {
             $relativePath = '/path/to/file.pdf';
             $absolutePath = \Yii::$app->get($this->getLocalFs())->path . $relativePath;
             if (!FileHelper::createDirectory(dirname($absolutePath))) {
                 return false;
             }
             if ($this->file->saveAs($absolutePath) && $this->moveLocalFileToStorage($relativePath)) {
                 return true;
             }
             $this->addError('file', \Yii::t('model','Error while uploading file'));
         }
         return false;
     }

     public function beforeDelete()
     {
         if (!$this->deleteFromStorage('/path/to/file.pdf')) {
             return false;
         }
         return parent::beforeDelete();
     }
 }
```

In your controller you just call the method moveLocalFileToStorage

```
 namespace example\namespace\controllers;

 use my\namespace\models\MyModel;
 use yii\web\Controller;
 use yii\web\UploadedFile;
 use Yii;

 class MyController extends Controller
 {
     public function actionUpload()
     {
         $model = new MyModel();
         if (Yii::$app->getRequest()->getIsPost()) {
             $model->file = UploadedFile::getInstance($model, 'file');
             if ($model->upload()) {
                 return $this->redirect(['upload']);
             }
         }
         return $this->render('upload', ['model' => $model]);
     }
 }
```

Your view file can look something like this

```
use yii\helpers\Html;
use yii\widgets\ActiveForm;

$form = ActiveForm::begin();
echo $form->field($model, 'file')->fileInput(['accept' => 'application/pdf']);
echo Html::submitButton();
ActiveForm::end();
```

Note: This is a very basic example. This may not suit your needs. Please do not blindly copy and paste it

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

2

Last Release

1538d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07b2ebef20cf3f8b95894ff50fdb0ba46cf04c8d74ffbb6a4e724af8569a8aec?d=identicon)[eluhr](/maintainers/eluhr)

---

Top Contributors

[![eluhr](https://avatars.githubusercontent.com/u/13000805?v=4)](https://github.com/eluhr "eluhr (6 commits)")

---

Tags

yii2filefly

### Embed Badge

![Health badge](/badges/eluhr-yii2-fileflyupload/health.svg)

```
[![Health](https://phpackages.com/badges/eluhr-yii2-fileflyupload/health.svg)](https://phpackages.com/packages/eluhr-yii2-fileflyupload)
```

###  Alternatives

[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
