PHPackages                             creocoder/yii2-flysystem - 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. creocoder/yii2-flysystem

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

creocoder/yii2-flysystem
========================

The flysystem extension for the Yii framework

1.2.0(2y ago)2931.7M↓16.3%79[12 issues](https://github.com/creocoder/yii2-flysystem/issues)20BSD-3-ClausePHP

Since Feb 9Pushed 2mo ago20 watchersCompare

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

READMEChangelog (10)Dependencies (12)Versions (22)Used By (20)

Flysystem Extension for Yii 2
=============================

[](#flysystem-extension-for-yii-2)

[![Code Quality](https://camo.githubusercontent.com/9ced17282665d0b255d65006135772c0f7bb010901fc4e1dbaf4d683bae3752f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6372656f636f6465722f796969322d666c7973797374656d2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/creocoder/yii2-flysystem/?branch=master)[![Packagist Version](https://camo.githubusercontent.com/d8700bb4b9fb726a4a4c7577bdea5438c9248e070ebe94beccac5255e665b0ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372656f636f6465722f796969322d666c7973797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creocoder/yii2-flysystem)[![Total Downloads](https://camo.githubusercontent.com/46f51e71c2e2bbc76ee59dbf011a19993979dc462724c4e615d304c9c0ed70d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372656f636f6465722f796969322d666c7973797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creocoder/yii2-flysystem)

This extension provides [Flysystem](http://flysystem.thephpleague.com/) integration for the Yii framework. [Flysystem](http://flysystem.thephpleague.com/) is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

**This version requires Flysystem 3.x and PHP 8.1+**

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require creocoder/yii2-flysystem
```

or add

```
"creocoder/yii2-flysystem": "^2.0"

```

to the `require` section of your `composer.json` file.

Configuring
-----------

[](#configuring)

### Local filesystem

[](#local-filesystem)

Configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => \creocoder\flysystem\LocalFilesystem::class,
            'path' => '@webroot/files',
        ],
    ],
];
```

### FTP filesystem

[](#ftp-filesystem)

Either run

```
$ composer require league/flysystem-ftp
```

or add

```
"league/flysystem-ftp": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'ftpFs' => [
            'class' => \creocoder\flysystem\FtpFilesystem::class,
            'host' => 'ftp.example.com',
            // 'port' => 21,
            // 'username' => 'your-username',
            // 'password' => 'your-password',
            // 'ssl' => true,
            // 'timeout' => 90,
            // 'root' => '/path/to/root',
            // 'passive' => true,
        ],
    ],
];
```

### In-Memory filesystem

[](#in-memory-filesystem)

Configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'memoryFs' => [
            'class' => \creocoder\flysystem\InMemoryFilesystem::class,
        ],
    ],
];
```

### AWS S3 filesystem

[](#aws-s3-filesystem)

Either run

```
$ composer require league/flysystem-aws-s3-v3
```

or add

```
"league/flysystem-aws-s3-v3": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'awss3Fs' => [
            'class' => \creocoder\flysystem\AwsS3Filesystem::class,
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            'region' => 'your-region',
            // 'version' => 'latest',
            // 'prefix' => 'your-prefix',
            // 'endpoint' => 'http://my-custom-url'
        ],
    ],
];
```

### Azure Blob Storage filesystem

[](#azure-blob-storage-filesystem)

Either run

```
$ composer require league/flysystem-azure-blob-storage
```

or add

```
"league/flysystem-azure-blob-storage": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'azureFs' => [
            'class' => \creocoder\flysystem\AzureFilesystem::class,
            'accountName' => 'your-account-name',
            'accountKey' => 'your-account-key',
            'container' => 'your-container',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### Dropbox filesystem

[](#dropbox-filesystem)

Either run

```
$ composer require spatie/flysystem-dropbox
```

or add

```
"spatie/flysystem-dropbox": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'dropboxFs' => [
            'class' => \creocoder\flysystem\DropboxFilesystem::class,
            'token' => 'your-token',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### Google Cloud Storage filesystem

[](#google-cloud-storage-filesystem)

Run

```
$ composer require league/flysystem-google-cloud-storage
```

and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'googleCloudFs' => [
            'class' => \creocoder\flysystem\GoogleCloudFilesystem::class,
            'projectId' => 'GOOGLE_PROJECT_ID',
            'bucket' => 'GOOGLE_BUCKET',
            'keyFilePath' => '@app/config/google-credentials.json',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

> Note: Credential configuration is read from the *keyFilePath*.

### GridFS filesystem

[](#gridfs-filesystem)

Either run

```
$ composer require league/flysystem-gridfs
```

or add

```
"league/flysystem-gridfs": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'gridFs' => [
            'class' => \creocoder\flysystem\GridFSFilesystem::class,
            'uri' => 'mongodb://localhost:27017',
            'database' => 'your-database',
            // 'bucketName' => 'fs',
        ],
    ],
];
```

### SFTP filesystem

[](#sftp-filesystem)

Either run

```
$ composer require league/flysystem-sftp-v3
```

or add

```
"league/flysystem-sftp-v3": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'sftpFs' => [
            'class' => \creocoder\flysystem\SftpFilesystem::class,
            'host' => 'sftp.example.com',
            // 'port' => 22,
            'username' => 'your-username',
            'password' => 'your-password',
            // 'privateKey' => '/path/to/or/contents/of/privatekey',
            // 'passphrase' => 'your-passphrase',
            // 'timeout' => 10,
            // 'root' => '/path/to/root',
        ],
    ],
];
```

### WebDAV filesystem

[](#webdav-filesystem)

Either run

```
$ composer require league/flysystem-webdav
```

or add

```
"league/flysystem-webdav": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'webdavFs' => [
            'class' => \creocoder\flysystem\WebDAVFilesystem::class,
            'baseUri' => 'your-base-uri',
            // 'userName' => 'your-user-name',
            // 'password' => 'your-password',
            // 'proxy' => 'your-proxy',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### ZipArchive filesystem

[](#ziparchive-filesystem)

Either run

```
$ composer require league/flysystem-ziparchive
```

or add

```
"league/flysystem-ziparchive": "^3.0"

```

to the `require` section of your `composer.json` file and configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'ziparchiveFs' => [
            'class' => \creocoder\flysystem\ZipArchiveFilesystem::class,
            'path' => '@webroot/files/archive.zip',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### Global visibility settings

[](#global-visibility-settings)

Configure `fsID` application component as follows

```
use League\Flysystem\Visibility;

return [
    //...
    'components' => [
        //...
        'fsID' => [
            //...
            'config' => [
                'visibility' => Visibility::PRIVATE,
            ],
        ],
    ],
];
```

Usage
-----

[](#usage)

### Writing files

[](#writing-files)

To write a file

```
Yii::$app->fs->write('filename.ext', 'contents');
```

To write a file using stream contents

```
$stream = fopen('/path/to/somefile.ext', 'r+');
Yii::$app->fs->writeStream('filename.ext', $stream);
```

### Reading files

[](#reading-files)

To read a file

```
$contents = Yii::$app->fs->read('filename.ext');
```

To retrieve a read-stream

```
$stream = Yii::$app->fs->readStream('filename.ext');
$contents = stream_get_contents($stream);
fclose($stream);
```

### Checking if a file exists

[](#checking-if-a-file-exists)

To check if a file exists

```
$exists = Yii::$app->fs->fileExists('filename.ext');
```

To check if a directory exists

```
$exists = Yii::$app->fs->directoryExists('path/to/directory');
```

### Deleting files

[](#deleting-files)

To delete a file

```
Yii::$app->fs->delete('filename.ext');
```

### Moving files

[](#moving-files)

To move a file

```
Yii::$app->fs->move('filename.ext', 'newname.ext');
```

### Copying files

[](#copying-files)

To copy a file

```
Yii::$app->fs->copy('filename.ext', 'copy.ext');
```

### Getting files mimetype

[](#getting-files-mimetype)

To get a file mimetype

```
$mimetype = Yii::$app->fs->mimeType('filename.ext');
```

### Getting files last modified timestamp

[](#getting-files-last-modified-timestamp)

To get a file last modified timestamp

```
$timestamp = Yii::$app->fs->lastModified('filename.ext');
```

### Getting files size

[](#getting-files-size)

To get a file size

```
$size = Yii::$app->fs->fileSize('filename.ext');
```

### Creating directories

[](#creating-directories)

To create a directory

```
Yii::$app->fs->createDirectory('path/to/directory');
```

Directories are also made implicitly when writing to a deeper path

```
Yii::$app->fs->write('path/to/filename.ext', 'contents');
```

### Deleting directories

[](#deleting-directories)

To delete a directory

```
Yii::$app->fs->deleteDirectory('path/to/directory');
```

### Managing visibility

[](#managing-visibility)

Visibility is the abstraction of file permissions across multiple platforms. Visibility can be either public or private.

```
use League\Flysystem\Visibility;

Yii::$app->fs->write('filename.ext', 'contents', [
    'visibility' => Visibility::PRIVATE
]);
```

You can also change and check visibility of existing files

```
use League\Flysystem\Visibility;

if (Yii::$app->fs->visibility('filename.ext') === Visibility::PRIVATE) {
    Yii::$app->fs->setVisibility('filename.ext', Visibility::PUBLIC);
}
```

### Listing contents

[](#listing-contents)

To list contents

```
$contents = Yii::$app->fs->listContents('', false);

foreach ($contents as $item) {
    echo $item->path();
    echo $item->isFile() ? 'file' : 'directory';
}
```

By default Flysystem lists the top directory non-recursively. You can supply a directory name and recursive boolean to get more precise results

```
$contents = Yii::$app->fs->listContents('path/to/directory', true);
```

Upgrading from v1
-----------------

[](#upgrading-from-v1)

If you are upgrading from the Flysystem v1 version of this extension, please note the following breaking changes:

### Removed Features

[](#removed-features)

- **Caching**: The cached adapter is no longer available in Flysystem v3
- **Replication**: The replicate adapter is no longer available in Flysystem v3
- **Rackspace**: The Rackspace adapter has been removed as the service is discontinued
- **NullFilesystem**: Replaced with `InMemoryFilesystem`

### API Changes

[](#api-changes)

v1 Methodv3 Method`has($path)``fileExists($path)` / `directoryExists($path)``createDir($path)``createDirectory($path)``deleteDir($path)``deleteDirectory($path)``rename($path, $newpath)``move($source, $destination)``getTimestamp($path)``lastModified($path)``getMimetype($path)``mimeType($path)``getSize($path)``fileSize($path)``getVisibility($path)``visibility($path)``update()` / `put()``write()``updateStream()` / `putStream()``writeStream()`### Visibility Constants

[](#visibility-constants)

```
// Old (v1)
use League\Flysystem\AdapterInterface;
AdapterInterface::VISIBILITY_PRIVATE;
AdapterInterface::VISIBILITY_PUBLIC;

// New (v3)
use League\Flysystem\Visibility;
Visibility::PRIVATE;
Visibility::PUBLIC;
```

Donating
--------

[](#donating)

Support this project and [others by creocoder](https://gratipay.com/creocoder/) via [gratipay](https://gratipay.com/creocoder/).

[![Support via Gratipay](https://camo.githubusercontent.com/1c5285a90da2f0b1ee32a7136cacdc9230404760abc467b90492670975ad5bd6/68747470733a2f2f63646e2e7261776769742e636f6d2f67726174697061792f67726174697061792d62616467652f322e332e302f646973742f67726174697061792e737667)](https://gratipay.com/creocoder/)

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance55

Moderate activity, may be stable

Popularity60

Solid adoption and visibility

Community42

Growing community involvement

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 80.3% 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 ~212 days

Recently: every ~496 days

Total

20

Last Release

83d ago

Major Versions

0.10.0 → 1.0.02020-09-17

1.2.0 → 2.0.0-beta12026-02-24

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/896494?v=4)[Alexander Kochetov](/maintainers/creocoder)[@creocoder](https://github.com/creocoder)

---

Top Contributors

[![creocoder](https://avatars.githubusercontent.com/u/896494?v=4)](https://github.com/creocoder "creocoder (151 commits)")[![schmunk42](https://avatars.githubusercontent.com/u/649031?v=4)](https://github.com/schmunk42 "schmunk42 (22 commits)")[![jc-67degrees](https://avatars.githubusercontent.com/u/85416543?v=4)](https://github.com/jc-67degrees "jc-67degrees (3 commits)")[![mikk150](https://avatars.githubusercontent.com/u/4953629?v=4)](https://github.com/mikk150 "mikk150 (3 commits)")[![pgaultier](https://avatars.githubusercontent.com/u/545714?v=4)](https://github.com/pgaultier "pgaultier (2 commits)")[![kesselb](https://avatars.githubusercontent.com/u/3902676?v=4)](https://github.com/kesselb "kesselb (2 commits)")[![dizews](https://avatars.githubusercontent.com/u/452641?v=4)](https://github.com/dizews "dizews (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![handcode](https://avatars.githubusercontent.com/u/825574?v=4)](https://github.com/handcode "handcode (1 commits)")[![huiyang](https://avatars.githubusercontent.com/u/517651?v=4)](https://github.com/huiyang "huiyang (1 commits)")[![k-timoshenko](https://avatars.githubusercontent.com/u/3259675?v=4)](https://github.com/k-timoshenko "k-timoshenko (1 commits)")

---

Tags

ftpfilesystemFlysystems3awssftpfilesazureWebDAVyii2dropboxrackspaceGridFScopy.com

### Embed Badge

![Health badge](/badges/creocoder-yii2-flysystem/health.svg)

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)

PHPackages © 2026

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