PHPackages                             mheads/yii2-filestorage - 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. mheads/yii2-filestorage

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

mheads/yii2-filestorage
=======================

File storage

1.0.8(1y ago)01.3k↓11.1%MITPHP

Since Jul 1Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (11)Used By (0)

yii2-filestorage
================

[](#yii2-filestorage)

Базовая конфигурация
--------------------

[](#базовая-конфигурация)

Добавьте миграции в ваше приложение, отредактируйте конфигурационный файл консоли, чтобы настроить миграцию пространства имен:

```
'controllerMap' => [
    // ...
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => null,
        'migrationNamespaces' => [
            // ...
            'mheads\filestorage\migrations',
        ],
    ],
],
```

Базовая конфигурация приложения:

```
const MHEADS_FILE_STORAGE_COMPONENT_NAME = 'fileStorage';

$config = [
    //...
    'components' => [
        //...
        MHEADS_FILE_STORAGE_COMPONENT_NAME => [
            'class' => \mheads\filestorage\Storage::class,
            'stores'           => [
                'upload' => [
                    'class'           => \mheads\filestorage\stores\fileSystem\FileSystemStore::class,
                    'baseUrl'         => '/upload',
                    'basePath'        => __DIR__.'/../../upload',
                    'basePrivatePath' => __DIR__.'/../../private_upload',
                    'isHttps'         => true,
                    'host'            => 'static.example.com',
                ],
            ],
            'defaultStoreName' => 'upload',
            'strictRemove'     => false,
        ],
    ]
];
```

Базовое использование
---------------------

[](#базовое-использование)

Добавление файла:

```
$uploadedFile = \yii\web\UploadedFile::getInstanceByName('picture');
$file = \mheads\filestorage\File::create(
	$uploadedFile,
	'product-pictures',
);
$file->add();
```

Получение файла:

```
use mheads\filestorage\File;

$file = File::find()->where([File::field_id => 123])->one();

$url = $file->getUrl();
$content = $file->getContent();
```

Удаление файла:

```
use mheads\filestorage\File;

$file = File::find()->where([File::field_id => 123])->one();
$file->remove();
```

Интеграция в Active record через поведение
------------------------------------------

[](#интеграция-в-active-record-через-поведение)

```
use mheads\filestorage\File;
use mheads\filestorage\behaviors\FileUploadBehavior;
use \yii\web\UploadedFile;

/**
 * @property ?int $id
 * @property ?string $name
 * @property ?UploadedFile|int $picture_id
 */
class Product extends \yii\db\ActiveRecord
{
    //......

    public function setPicture(?UploadedFile $file): void
    {
        $this->setAttribute('picture_id', $file);
    }

    public function getPicture()
    {
        return $this->hasOne(File::class, [File::field_id => 'picture_id']);
    }

    public function behaviors(): array
    {
        return [
            'pictureUpload' => [
                'class'     => FileUploadBehavior::class,
                'attribute' => 'picture_id',
                'isPrivate' => false,
                'groupName' => 'product-pictures',
            ],
        ];
    }

    //......
}
```

Поддержка нескольких хранилищ
-----------------------------

[](#поддержка-нескольких-хранилищ)

Конфиг:

```
const MHEADS_FILE_STORAGE_COMPONENT_NAME = 'fileStorage';

$config = [
    //...
    'components' => [
        //...
        MHEADS_FILE_STORAGE_COMPONENT_NAME => [
            'class' => \mheads\filestorage\Storage::class,
            'stores'           => [
                'upload' => [
                    'class'           => \mheads\filestorage\stores\fileSystem\FileSystemStore::class,
                    'baseUrl'         => '/upload',
                    'basePath'        => __DIR__.'/../../upload',
                    'basePrivatePath' => __DIR__.'/../../private_upload',
                    'isHttps'         => true,
                    'host'            => 'static.example.com',
                ],
                'upload2' => [
                    'class'           => \mheads\filestorage\stores\fileSystem\FileSystemStore::class,
                    'baseUrl'         => '/upload2',
                    'basePath'        => '/media/store/data/upload',
                    'basePrivatePath' => '/media/store/data/private_upload',
                    'isHttps'         => true,
                    'host'            => 'static2.example.com',
                ],
            ],
            'defaultStoreName' => 'upload',
            'strictRemove'     => false,
        ],
    ],
];
```

Добавление файла с указанием хранилища:

```
$uploadedFile = \yii\web\UploadedFile::getInstanceByName('picture');
$file = \mheads\filestorage\File::create(
	$uploadedFile,
	'product-pictures',
	'upload2', // store name
);
$file->add();
```

Поведение Active Record с указанием хранилища:

```
public function behaviors(): array
{
    return [
        'pictureUpload' => [
            'class'     => FileUploadBehavior::class,
            'attribute' => 'picture_id',
            'isPrivate' => false,
            'groupName' => 'product-pictures',
            'storeName' => 'upload2', // store name
        ],
    ];
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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 ~96 days

Recently: every ~177 days

Total

10

Last Release

544d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8805360bd6ba1a19f70a9a23819afe7109a80ea0a4c387201f4fa986a50c75f8?d=identicon)[alse0017](/maintainers/alse0017)

---

Top Contributors

[![sa-machineheads](https://avatars.githubusercontent.com/u/22737984?v=4)](https://github.com/sa-machineheads "sa-machineheads (11 commits)")

---

Tags

yii2extensionfile managerfile storage

### Embed Badge

![Health badge](/badges/mheads-yii2-filestorage/health.svg)

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

###  Alternatives

[zxbodya/yii2-elfinder

Extension to use elFinder 1.x file manager in Yii2 application

1035.7k3](/packages/zxbodya-yii2-elfinder)[fedemotta/yii2-aws-sdk

This extension provides the AWS SDK integration for the Yii2 framework

15430.4k2](/packages/fedemotta-yii2-aws-sdk)[rkit/filemanager-yii2

FileManager for Yii2

181.3k](/packages/rkit-filemanager-yii2)[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)
