PHP code example of impressiveweb / yandex-disk-flysystem

1. Go to this page and download the library: Download impressiveweb/yandex-disk-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/ */

    

impressiveweb / yandex-disk-flysystem example snippets


use ImpressiveWeb\YandexDisk\Client;
use League\Flysystem\Filesystem;
use ImpressiveWeb\Flysystem\YandexDiskAdapter;
use League\Flysystem\StorageAttributes;

// 1. Create a new client.
$client = new Client($accessToken);

// 2. Create an adapter. 
$adapter = new YandexDiskAdapter($client);

// 3. Create a filesystem.
$filesystem = new Filesystem($adapter);

// Get a list of directories in the root of your Application or Disk. 
$items = $filesystem
    ->listContents('/')
    ->filter(fn(StorageAttributes $attributes) => $attributes->isDir())
    ->map(fn(StorageAttributes $attributes) => $attributes->path())
    ->toArray()
;

// Get a list of files in a root of your Application or Disk. 
$items = $filesystem
    ->listContents('/')
    ->filter(fn(StorageAttributes $attributes) => $attributes->isFile())
    ->map(fn(StorageAttributes $attributes) => $attributes->path())
    ->toArray()
;