PHP code example of biller / yii2-flysystem

1. Go to this page and download the library: Download biller/yii2-flysystem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

biller / yii2-flysystem example snippets


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

use League\Flysystem\AdapterInterface;

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

use League\Flysystem\AdapterInterface;

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

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

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

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