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

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

goranmitev/yii2-flysystem
=========================

The flysystem extension for the Yii framework

0.8.4(9y ago)040BSD-3-ClausePHP

Since Feb 9Pushed 9y agoCompare

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

READMEChangelogDependencies (13)Versions (13)Used By (0)

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

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

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

[](#installation)

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

Either run

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

or add

```
"goranmitev/yii2-flysystem": "0.8.*"

```

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

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

[](#configuring)

### Local filesystem

[](#local-filesystem)

Configure application `components` as follows

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

### FTP filesystem

[](#ftp-filesystem)

Configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'ftpFs' => [
            'class' => 'creocoder\flysystem\FtpFilesystem',
            'host' => 'ftp.example.com',
            // 'port' => 21,
            // 'username' => 'your-username',
            // 'password' => 'your-password',
            // 'ssl' => true,
            // 'timeout' => 60,
            // 'root' => '/path/to/root',
            // 'permPrivate' => 0700,
            // 'permPublic' => 0744,
            // 'passive' => false,
            // 'transferMode' => FTP_TEXT,
        ],
    ],
];
```

### NULL filesystem

[](#null-filesystem)

Configure application `components` as follows

```
return [
    //...
    'components' => [
        //...
        'nullFs' => [
            'class' => 'creocoder\flysystem\NullFilesystem',
        ],
    ],
];
```

### AWS S3 filesystem

[](#aws-s3-filesystem)

Either run

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

or add

```
"league/flysystem-aws-s3-v3": "~1.0"

```

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

```
return [
    //...
    'components' => [
        //...
        'awss3Fs' => [
            'class' => 'creocoder\flysystem\AwsS3Filesystem',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            'region' => 'your-region',
            'version' => 'latest',
            // 'baseUrl' => 'your-base-url',
            // 'prefix' => 'your-prefix',
            // 'options' => [],
        ],
    ],
];
```

### Azure filesystem

[](#azure-filesystem)

Add the following to the `repositories` section of your `composer.json`

```
{
    "type": "pear",
    "url": "http://pear.php.net"
}

```

Either run

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

or add

```
"league/flysystem-azure": "~1.0"

```

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

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

### Copy filesystem

[](#copy-filesystem)

Either run

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

or add

```
"league/flysystem-copy": "~1.0"

```

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

```
return [
    //...
    'components' => [
        //...
        'copyFs' => [
            'class' => 'creocoder\flysystem\CopyFilesystem',
            'consumerKey' => 'your-consumer-key',
            'consumerSecret' => 'your-consumer-secret',
            'accessToken' => 'your-access-token',
            'tokenSecret' => 'your-token-secret',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### Dropbox filesystem

[](#dropbox-filesystem)

Either run

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

or add

```
"league/flysystem-dropbox": "~1.0"

```

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

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

### GridFS filesystem

[](#gridfs-filesystem)

Either run

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

or add

```
"league/flysystem-gridfs": "~1.0"

```

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

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

### Rackspace filesystem

[](#rackspace-filesystem)

Either run

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

or add

```
"league/flysystem-rackspace": "~1.0"

```

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

```
return [
    //...
    'components' => [
        //...
        'rackspaceFs' => [
            'class' => 'creocoder\flysystem\RackspaceFilesystem',
            'endpoint' => 'your-endpoint',
            'region' => 'your-region',
            'username' => 'your-username',
            'apiKey' => 'your-api-key',
            'container' => 'your-container',
            // 'prefix' => 'your-prefix',
        ],
    ],
];
```

### SFTP filesystem

[](#sftp-filesystem)

Either run

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

or add

```
"league/flysystem-sftp": "~1.0"

```

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

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

### WebDAV filesystem

[](#webdav-filesystem)

Either run

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

or add

```
"league/flysystem-webdav": "~1.0"

```

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

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

### ZipArchive filesystem

[](#ziparchive-filesystem)

Either run

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

or add

```
"league/flysystem-ziparchive": "~1.0"

```

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

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

### Caching feature

[](#caching-feature)

Either run

```
$ composer require league/flysystem-cached-adapter
```

or add

```
"league/flysystem-cached-adapter": "~1.0"

```

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

```
return [
    //...
    'components' => [
        //...
        'fsID' => [
            //...
            'cache' => 'cacheID',
            // 'cacheKey' => 'flysystem',
            // 'cacheDuration' => 3600,
        ],
    ],
];
```

### Replication feature

[](#replication-feature)

Either run

```
$ composer require league/flysystem-replicate-adapter
```

or add

```
"league/flysystem-replicate-adapter": "~1.0"

```

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

```
return [
    //...
    'components' => [
        //...
        'fsID' => [
            //...
            'replica' => 'anotherFsID',
        ],
    ],
];
```

### Global visibility settings

[](#global-visibility-settings)

Configure `fsID` application component as follows

```
return [
    //...
    'components' => [
        //...
        'fsID' => [
            //...
            'config' => [
                'visibility' => \League\Flysystem\AdapterInterface::VISIBILITY_PRIVATE,
            ],
        ],
    ],
];
```

Usage
-----

[](#usage)

### Writing files

[](#writing-files)

To write file

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

To write file using stream contents

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

### Updating files

[](#updating-files)

To update file

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

To update file using stream contents

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

### Writing or updating files

[](#writing-or-updating-files)

To write or update file

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

To write or update file using stream contents

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

### Reading files

[](#reading-files)

To read 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->has('filename.ext');
```

### Deleting files

[](#deleting-files)

To delete file

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

### Reading and deleting files

[](#reading-and-deleting-files)

To read and delete file

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

### Renaming files

[](#renaming-files)

To rename file

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

### Getting files mimetype

[](#getting-files-mimetype)

To get file mimetype

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

### Getting files timestamp

[](#getting-files-timestamp)

To get file timestamp

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

### Getting files size

[](#getting-files-size)

To get file size

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

### Creating directories

[](#creating-directories)

To create directory

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

Directories are also made implicitly when writing to a deeper path

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

### Deleting directories

[](#deleting-directories)

To delete directory

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

### Managing visibility

[](#managing-visibility)

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

```
use League\Flysystem\AdapterInterface;

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

You can also change and check visibility of existing files

```
use League\Flysystem\AdapterInterface;

if (Yii::$app->fs->getVisibility('filename.ext') === AdapterInterface::VISIBILITY_PRIVATE) {
    Yii::$app->fs->setVisibility('filename.ext', AdapterInterface::VISIBILITY_PUBLIC);
}
```

### Listing contents

[](#listing-contents)

To list contents

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

foreach ($contents as $object) {
    echo $object['basename']
        . ' is located at' . $object['path']
        . ' and is a ' . $object['type'];
}
```

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);
```

### Listing paths

[](#listing-paths)

To list paths

```
$paths = Yii::$app->fs->listPaths();

foreach ($paths as $path) {
    echo $path;
}
```

### Listing with ensured presence of specific metadata

[](#listing-with-ensured-presence-of-specific-metadata)

To list with ensured presence of specific metadata

```
$listing = Yii::$app->fs->listWith(
    ['mimetype', 'size', 'timestamp'],
    'optional/path/to/directory',
    true
);

foreach ($listing as $object) {
    echo $object['path'] . ' has mimetype: ' . $object['mimetype'];
}
```

### Getting file info with explicit metadata

[](#getting-file-info-with-explicit-metadata)

To get file info with explicit metadata

```
$info = Yii::$app->fs->getWithMetadata('path/to/filename.ext', ['timestamp', 'mimetype']);
echo $info['mimetype'];
echo $info['timestamp'];
```

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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~176 days

Total

12

Last Release

3391d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d7be1e4c1f3b884c608f132f7bce075f44c61456a635fa7eb37c26a6c7088d6?d=identicon)[goranmitev](/maintainers/goranmitev)

---

Top Contributors

[![creocoder](https://avatars.githubusercontent.com/u/896494?v=4)](https://github.com/creocoder "creocoder (149 commits)")

---

Tags

ftpfilesystemFlysystems3awssftpfilesazureWebDAVyii2dropboxrackspaceGridFScopy.com

### Embed Badge

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

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

###  Alternatives

[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[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.6M788](/packages/league-flysystem-aws-s3-v3)

PHPackages © 2026

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