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

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

diecoding/yii2-flysystem
========================

The League Flysystem for local and remote filesystems library for Yii2

v1.7.4(1y ago)515.3k↓23.2%12MITPHPPHP &gt;=8.0

Since May 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/wanforge/yii2-flysystem)[ Packagist](https://packagist.org/packages/diecoding/yii2-flysystem)[ Docs](https://github.com/sugeng-sulistiyawan/yii2-flysystem)[ GitHub Sponsors](https://github.com/sponsors/sugeng-sulistiyawan)[ RSS](/packages/diecoding-yii2-flysystem/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (21)Used By (2)

Yii2 Flysystem
==============

[](#yii2-flysystem)

The League Flysystem for local and remote filesystems library for Yii2.

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

[![Latest Stable Version](https://camo.githubusercontent.com/468070ef6f3ccd05d13b3a68d60df1c04d17445251c652938034ff80f2449dcc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646965636f64696e672f796969322d666c7973797374656d3f6c6162656c3d737461626c65)](https://packagist.org/packages/diecoding/yii2-flysystem)[![Total Downloads](https://camo.githubusercontent.com/8b97f9b6676a500af3a66e659d35a9c11c6828e002a3ef38c9d19918430ba0d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965636f64696e672f796969322d666c7973797374656d)](https://packagist.org/packages/diecoding/yii2-flysystem)[![Latest Stable Release Date](https://camo.githubusercontent.com/19675f48f7db5bf191f563a9ba37983b30b27fea9de8a76be0b028c81034ece0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f737567656e672d73756c69737469796177616e2f796969322d666c7973797374656d)](https://github.com/sugeng-sulistiyawan/yii2-flysystem)[![Quality Score](https://camo.githubusercontent.com/b26505a995dd27d3365b8aeda10782380f7b15312586f58a4c8840f2260bc729/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f737567656e672d73756c69737469796177616e2f796969322d666c7973797374656d)](https://scrutinizer-ci.com/g/sugeng-sulistiyawan/yii2-flysystem)[![Build Status](https://camo.githubusercontent.com/1b5900387216f3954169340b88a585be2159392e7d3363faecbeaeb22ad506a6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f737567656e672d73756c69737469796177616e2f796969322d666c7973797374656d)](https://app.travis-ci.com/sugeng-sulistiyawan/yii2-flysystem)[![License](https://camo.githubusercontent.com/d1f0f2bad98a53de80df225e0d05f28a8f8e72f269c80ff5752e2f7dd81a561a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f737567656e672d73756c69737469796177616e2f796969322d666c7973797374656d)](https://github.com/sugeng-sulistiyawan/yii2-flysystem)[![PHP Version Require](https://camo.githubusercontent.com/8d7e9af28bf9d0cf9bb4a6e8300cd51065803a7a69f991c284c1aa62d5831317/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f646965636f64696e672f796969322d666c7973797374656d2f7068703f636f6c6f723d366637336136)](https://packagist.org/packages/diecoding/yii2-flysystem)

> Yii2 Flysystem uses [league/flysystem](https://github.com/thephpleague/flysystem)

Table of Contents
-----------------

[](#table-of-contents)

- [Yii2 Flysystem](#yii2-flysystem)
    - [Table of Contents](#table-of-contents)
    - [Instalation](#instalation)
    - [Dependencies](#dependencies)
    - [Dev. Dependencies](#dev-dependencies)
    - [Configuration](#configuration)
        - [Local Filesystem](#local-filesystem)
        - [AsyncAws S3 Filesystem](#asyncaws-s3-filesystem)
        - [AWS S3 Filesystem](#aws-s3-filesystem)
        - [Google Cloud Storage Filesystem](#google-cloud-storage-filesystem)
        - [FTP Filesystem](#ftp-filesystem)
        - [SFTP Filesystem](#sftp-filesystem)
        - [WebDAV Filesystem](#webdav-filesystem)
        - [ZipArchive Filesystem](#ziparchive-filesystem)
        - [Google Drive Filesystem](#google-drive-filesystem)
    - [Additional Configuration](#additional-configuration)
        - [URL File Action Settings](#url-file-action-settings)
        - [Global Visibility Settings](#global-visibility-settings)
    - [Usage](#usage)
        - [Writing or Updating Files](#writing-or-updating-files)
        - [Reading Files](#reading-files)
        - [Checking if a File Exists](#checking-if-a-file-exists)
        - [Deleting Files](#deleting-files)
        - [Getting Files Mime Type](#getting-files-mime-type)
        - [Getting Files Timestamp / Last Modified](#getting-files-timestamp--last-modified)
        - [Getting Files Size](#getting-files-size)
        - [Creating Directories](#creating-directories)
        - [Checking if a Directory Exists](#checking-if-a-directory-exists)
        - [Deleting Directories](#deleting-directories)
        - [Checking if a File or Directory Exists](#checking-if-a-file-or-directory-exists)
        - [Managing Visibility](#managing-visibility)
        - [Listing contents](#listing-contents)
        - [Copy Files or Directories](#copy-files-or-directories)
        - [Move Files or Directories](#move-files-or-directories)
        - [Get URL Files](#get-url-files)
        - [Get URL Temporary Files / Presigned URL](#get-url-temporary-files--presigned-url)
        - [Get MD5 Hash File Contents](#get-md5-hash-file-contents)
    - [Using Traits](#using-traits)
        - [Model Trait](#model-trait)
            - [Using Trait Methods](#using-trait-methods)
            - [Overriding Trait Methods](#overriding-trait-methods)
                - [getFsComponent](#getfscomponent)
                - [attributePaths](#attributepaths)
                - [getPresignedUrlDuration](#getpresignedurlduration)

Instalation
-----------

[](#instalation)

Package is available on [Packagist](https://packagist.org/packages/diecoding/yii2-flysystem), you can install it using [Composer](https://getcomposer.org).

```
composer require diecoding/yii2-flysystem "^1.0"
```

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

```
"diecoding/yii2-flysystem": "^1.0"
```

Dependencies
------------

[](#dependencies)

- PHP 8.0+
- [yiisoft/yii2](https://github.com/yiisoft/yii2)
- [league/flysystem](https://github.com/thephpleague/flysystem)
- [league/flysystem-path-prefixing](https://github.com/thephpleague/flysystem-path-prefixing)

Dev. Dependencies
-----------------

[](#dev-dependencies)

- [league/flysystem-async-aws-s3](https://github.com/thephpleague/flysystem-async-aws-s3)
- [league/flysystem-aws-s3-v3](https://github.com/thephpleague/flysystem-aws-s3-v3)
- [league/flysystem-google-cloud-storage](https://github.com/thephpleague/flysystem-google-cloud-storage)
- [league/flysystem-ftp](https://github.com/thephpleague/flysystem-ftp)
- [league/flysystem-sftp-v3](https://github.com/thephpleague/flysystem-sftp-v3)
- [league/flysystem-webdav](https://github.com/thephpleague/flysystem-webdav)
- [league/flysystem-ziparchive](https://github.com/thephpleague/flysystem-ziparchive)
- [masbug/flysystem-google-drive-ext](https://github.com/masbug/flysystem-google-drive-ext)

Configuration
-------------

[](#configuration)

### Local Filesystem

[](#local-filesystem)

Configure application `components` as follows

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\LocalComponent::class,
            'path' => dirname(dirname(__DIR__)) . '/storage', // or you can use @alias
            'secret' => 'my-secret', // for secure route url
            // 'action' => '/site/file', // action route
            // 'prefix' => '',
        ],
    ],
];
```

### AsyncAws S3 Filesystem

[](#asyncaws-s3-filesystem)

See: [league/flysystem-async-aws-s3](https://github.com/thephpleague/flysystem-async-aws-s3)

Either run

```
composer require league/flysystem-async-aws-s3:^3.0
```

or add

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

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\AsyncAwsS3Component::class,
            'endpoint' => 'http://your-endpoint',
            'bucket' => 'my-bucket',
            'accessKeyId' => 'my-key',
            'accessKeySecret' => 'my-secret',
            // 'sharedCredentialsFile' => '~/.aws/credentials',
            // 'sharedConfigFile' => '~/.aws/config',
            // 'region' => 'us-east-1',
            // 'endpointDiscoveryEnabled' => false,
            // 'pathStyleEndpoint' => false,
            // 'sendChunkedBody' => false,
            // 'debug' => false,
            // 'prefix' => '',
        ],
    ],
];
```

### AWS S3 Filesystem

[](#aws-s3-filesystem)

See: [league/flysystem-aws-s3-v3](https://github.com/thephpleague/flysystem-aws-s3-v3)

Either run

```
composer require league/flysystem-aws-s3-v3:^3.0
```

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' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\AwsS3Component::class,
            'endpoint' => 'http://your-endpoint',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            // 'region' => 'us-east-1',
            // 'version' => 'latest',
            // 'usePathStyleEndpoint' => false,
            // 'streamReads' => false,
            // 'options' => [],
            // 'credentials' => [],
            // 'debug' => false,
            // 'prefix' => '',
        ],
    ],
];
```

### Google Cloud Storage Filesystem

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

See: [league/flysystem-google-cloud-storage](https://github.com/thephpleague/flysystem-google-cloud-storage)

Either run

```
composer require league/flysystem-google-cloud-storage:^3.0
```

or add

```
"league/flysystem-google-cloud-storage": "^3.0"
```

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\GoogleCloudStorageComponent::class,
            'bucket' => 'your-bucket',
            // 'apiEndpoint' => '',
            // 'projectId' => '',
            // 'authCache' => null,
            // 'authCacheOptions' => [],
            // 'authHttpHandler' => function () {},
            // 'credentialsFetcher' => null,
            // 'httpHandler' => function () {},
            // 'keyFile' => '',
            'keyFilePath' => __DIR__ . '/gcs_credentials.json',
            // 'requestTimeout' => 0,
            // 'retries' => 0,
            // 'scopes' => [],
            // 'quotaProject' => '',
            // 'userProject' => false,
            // 'prefix' => '',
        ],
    ],
];
```

### FTP Filesystem

[](#ftp-filesystem)

See: [league/flysystem-ftp](https://github.com/thephpleague/flysystem-ftp)

Either run

```
composer require league/flysystem-ftp:^3.0
```

or add

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

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\FtpComponent::class,
            'host' => 'hostname',
            'root' => '/root/path/', // or you can use @alias
            'username' => 'username',
            'password' => 'password',
            // 'port' => 21,
            // 'ssl' => false,
            // 'timeout' => 90,
            // 'utf8' => false,
            // 'passive' => true,
            // 'transferMode' => FTP_BINARY,
            // 'systemType' => null, // 'windows' or 'unix'
            // 'ignorePassiveAddress' => null, // true or false
            // 'timestampsOnUnixListingsEnabled' => false,
            // 'recurseManually' => true,
            // 'useRawListOptions' => null, // true or false
            // 'passphrase' => 'secret', // for secure route url
            // 'action' => '/site/file', // action route
            // 'prefix' => '',
        ],
    ],
];
```

### SFTP Filesystem

[](#sftp-filesystem)

See: [league/flysystem-sftp-v3](https://github.com/thephpleague/flysystem-sftp-v3)

Either run

```
composer require league/flysystem-sftp-v3:^3.0
```

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' => [
        'fs' => [
            'class' => \diecoding\flysystem\SftpComponent::class,
            'host' => 'hostname',
            'username' => 'username',
            'password' => null, // password (optional, default: null) set to null if privateKey is used
            // 'privateKey' => '/path/to/my/private_key', // private key (optional, default: null) can be used instead of password, set to null if password is set
            // 'passphrase' => 'super-secret-password', // passphrase (optional, default: null), set to null if privateKey is not used or has no passphrase
            // 'port' => 22,
            // 'useAgent' => true,
            // 'timeout' => 10,
            // 'maxTries' => 4,
            // 'hostFingerprint' => null,
            // 'connectivityChecker' => null, // connectivity checker (must be an implementation of `League\Flysystem\PhpseclibV2\ConnectivityChecker` to check if a connection can be established (optional, omit if you don't need some special handling for setting reliable connections)
            // 'preferredAlgorithms' => [],
            // 'root' => '/root/path/', // or you can use @alias
            // 'action' => '/site/file', // action route
            // 'prefix' => '',
        ],
    ],
];
```

### WebDAV Filesystem

[](#webdav-filesystem)

See: [league/flysystem-webdav](https://github.com/thephpleague/flysystem-webdav)

Either run

```
composer require league/flysystem-webdav:^3.0
```

or add

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

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\WebDavComponent::class,
            'baseUri' => 'http://your-webdav-server.org/',
            'userName' => 'your_user',
            'password' => 'superSecret1234',
            // 'proxy' => '',
            // 'authType' => \Sabre\DAV\Client::AUTH_BASIC,
            // 'encoding' => \Sabre\DAV\Client::ENCODING_IDENTITY,
            // 'prefix' => '',
        ],
    ],
];
```

### ZipArchive Filesystem

[](#ziparchive-filesystem)

See: [league/flysystem-ziparchive](https://github.com/thephpleague/flysystem-ziparchive)

Either run

```
composer require league/flysystem-ziparchive:^3.0
```

or add

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

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\ZipArchiveComponent::class,
            'pathToZip' => dirname(dirname(__DIR__)) . '/storage.zip', // or you can use @alias
            'secret' => 'my-secret', // for secure route url
            // 'action' => '/site/file', // action route
            // 'prefix' => '', // root directory inside zip file
        ],
    ],
];
```

### Google Drive Filesystem

[](#google-drive-filesystem)

See: [masbug/flysystem-google-drive-ext](https://github.com/masbug/flysystem-google-drive-ext)

Either run

```
composer require masbug/flysystem-google-drive-ext:^2.0
```

or add

```
"masbug/flysystem-google-drive-ext": "^2.0"
```

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

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            'class' => \diecoding\flysystem\GoogleDriveComponent::class,
            'applicationName' => 'My Google Drive App',
            'clientId' => '',
            'clientSecret' => '',
            'refreshToken' => '',
            // 'teamDriveId' => '',
            // 'sharedFolderId' => '',
            // 'options' => [],
            'secret' => 'my-secret', // for secure route url
            // 'action' => '/site/file', // action route
            // 'prefix' => '',
        ],
    ],
];
```

Additional Configuration
------------------------

[](#additional-configuration)

### URL File Action Settings

[](#url-file-action-settings)

The following adapters have URL File Action generation capabilities:

- Local Component
- FTP Component
- SFTP Component
- Google Drive Component

Configure `action` in `controller` as follows

> This example at `SiteController` for `/site/file`

```
class SiteController extends Controller
{
    //...
    public function actions()
    {
        return [
            // ...
            'file' => [
                'class' => \diecoding\flysystem\actions\FileAction::class,
                // 'component' => 'fs',
            ],
        ];
    }
}
```

> Remember to configure `action` key in `fs` application components as follows

```
return [
    // ...
    'components' => [
        // ...
        'fs' => [
            // ...
            'action' => '/site/file', // action for get url file
        ],
    ],
];
```

### Global Visibility Settings

[](#global-visibility-settings)

Configure `fs` application component as follows

```
return [
    //...
    'components' => [
        //...
        'fs' => [
            //...
            'config' => [
                'visibility' => \League\Flysystem\Visibility::PRIVATE,
            ],
        ],
    ],
];
```

Usage
-----

[](#usage)

### Writing or Updating Files

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

To write or update file

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

To write or update file using stream contents

```
$stream = fopen('/path/to/somefile.ext', 'r+');
Yii::$app->fs->writeStream('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->fileExists('filename.ext');
```

### Deleting Files

[](#deleting-files)

To delete file

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

### Getting Files Mime Type

[](#getting-files-mime-type)

To get file mime type

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

### Getting Files Timestamp / Last Modified

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

To get file timestamp

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

### Getting Files Size

[](#getting-files-size)

To get file size

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

### Creating Directories

[](#creating-directories)

To create 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');
```

### Checking if a Directory Exists

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

To check if a directory exists

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

### Deleting Directories

[](#deleting-directories)

To delete directory

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

### Checking if a File or Directory Exists

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

To check if a file or directory exists

```
$exists = Yii::$app->fs->has('path/to/directory/filename.ext');
```

### Managing Visibility

[](#managing-visibility)

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

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

You can also change and check visibility of existing files

```
if (Yii::$app->fs->visibility('filename.ext') === \League\Flysystem\Visibility::PRIVATE) {
    Yii::$app->fs->setVisibility('filename.ext', \League\Flysystem\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);
```

### Copy Files or Directories

[](#copy-files-or-directories)

To copy contents

```
Yii::$app->fs->copy('path/from/directory/filename.ext', 'path/to/directory/filename.ext', [
    'visibility' => \League\Flysystem\Visibility::PRIVATE
]);
```

### Move Files or Directories

[](#move-files-or-directories)

To move contents

```
Yii::$app->fs->move('path/from/directory/filename.ext', 'path/to/directory/filename.ext', [
    'visibility' => \League\Flysystem\Visibility::PRIVATE
]);
```

### Get URL Files

[](#get-url-files)

To get url contents

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

### Get URL Temporary Files / Presigned URL

[](#get-url-temporary-files--presigned-url)

To get temporary url contents

```
$expiresAt = new \DateTimeImmutable('+10 Minutes');

Yii::$app->fs->temporaryUrl('path/to/directory/filename.ext', $expiresAt);
```

The `$expiresAt` should be a valid and instance of `PHP DateTimeInterface`. Read [PHP documentation](https://www.php.net/manual/en/class.datetimeinterface.php) for details.

### Get MD5 Hash File Contents

[](#get-md5-hash-file-contents)

To get MD5 hash of the file contents

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

Using Traits
------------

[](#using-traits)

### Model Trait

[](#model-trait)

Attach the Trait to the `Model/ActiveRecord` with some media attribute that will be saved in Flysystem (fs):

```
/**
 * @property string|null $file
 */
class Model extends \yii\db\ActiveRecord
{
    use \diecoding\flysystem\traits\ModelTrait;

    // ...

    public function rules()
    {
        return [
            ['image', 'string'], // Stores the filename
        ];
    }

    /**
     * @inheritdoc
     */
    protected function attributePaths()
    {
        return [
            'image' => 'images/'
        ];
    }

    // ...
}
```

Override the `attributePaths()` method to change the base path where the files will be saved on Flysystem (fs).

- You can map a different path to each file attribute of your `Model/ActiveRecord`.

#### Using Trait Methods

[](#using-trait-methods)

```
$image = \yii\web\UploadedFile::getInstance($model, 'image');

// Save image_thumb.* to Flysystem (fs) on //my_bucket/images/ path
// The extension of the file will be determined by the submitted file type
// This allows multiple file types upload (png,jpg,gif,...)
// $model->image will hold "image_thumb.png" after this call finish with success
$model->saveUploadedFile($image, 'image', 'image_thumb');
$model->save();

// Save image_thumb.png to Flysystem (fs) on //my_bucket/images/ path
// The extension of the file will be determined by the submitted file type
// This force the extension to *.png
$model->saveUploadedFile($image, 'image', 'image_thumb.png', false);
$model->save();

// Remove the file with named saved on the image attribute
// Continuing the example, here "//my_bucket/images/my_image.png" will be deleted from Flysystem (fs)
$model->removeFile('image');
$model->save();

// Get the URL to the image on Flysystem (fs)
$model->getFileUrl('image');

// Get the presigned URL to the image on Flysystem (fs)
// The default duration is "+5 Minutes"
$model->getFilePresignedUrl('image');
```

#### Overriding Trait Methods

[](#overriding-trait-methods)

##### getFsComponent

[](#getfscomponent)

The Flysystem (fs) MediaTrait depends on this component to be configured. The default configuration is to use this component on index `'fs'`, but you may use another value. For this cases, override the `getFsComponent()` method:

```
public function getFsComponent()
{
    return Yii::$app->get('my_fs_component');
}
```

##### attributePaths

[](#attributepaths)

The main method to override is `attributePaths()`, which defines a path in Flysystem (fs) for each attribute of yout model. Allowing you to save each attribute in a different Flysystem (fs) folder.

Here an example:

```
protected function attributePaths()
{
    return [
        'logo' => 'logos/',
        'badge' => 'images/badges/'
    ];
}

// or use another attribute, example: id
// ! Note: id must contain a value first if you don't want it to be empty

protected function attributePaths()
{
    return [
        'logo' => 'thumbnail/' . $this->id . '/logos/',
        'badge' => 'thumbnail/' . $this->id . '/images/badges/'
    ];
}
```

##### getPresignedUrlDuration

[](#getpresignedurlduration)

The default pressigned URL duration is set to "+5 Minutes", override this method and use your own expiration. Return must instance of `DateTimeInterface`

```
protected function getPresignedUrlDuration($attribute)
{
    return new \DateTimeImmutable('+2 Hours');
}

// or if you want to set the attribute differently

protected function getPresignedUrlDuration($attribute)
{
    switch ($attribute) {
        case 'badge':
            return new \DateTimeImmutable('+2 Hours');
            break;

        default:
            return new \DateTimeImmutable('+1 Days');
            break;
    }
}
```

The value should be a valid and instance of `PHP DateTimeInterface`. Read [PHP documentation](https://www.php.net/manual/en/class.datetimeinterface.php) for details.

---

Read more docs:

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

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

Recently: every ~2 days

Total

20

Last Release

570d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5fa8faeecf1f3d0da2d981ae5e4238e1590a7897b14b890663a0c49ef03e87a?d=identicon)[diecoding](/maintainers/diecoding)

---

Top Contributors

[![wanforge](https://avatars.githubusercontent.com/u/16300077?v=4)](https://github.com/wanforge "wanforge (125 commits)")

---

Tags

awscomponentextensionfilesfilesystemflysystemftpgoogle-cloud-storagegoogle-drive-api-v3s3sftpyii2ftpfilesystemFlysystems3awssftpfilesyii2extensioncomponent

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-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)
