PHP code example of dakword / yandexdisk-storage

1. Go to this page and download the library: Download dakword/yandexdisk-storage 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/ */

    

dakword / yandexdisk-storage example snippets


composer 

$config = [
    // option => default
    'visibility' => 'private', // 'public', 'private'
    'retain_visibility' => true,
    'checksum_algo' => 'md5', // 'md5', 'sha256'
];

$client = new Arhitector\Yandex\Disk('oauth-token');
$adapter = new YandexDiskStorageAdapter($client, $prefix = '/', $config);

$yandexDiskStorage = new League\Flysystem\Filesystem($adapter);

try {
    $content = $yandexDiskStorage->read('images/file.jpg');
} catch (FilesystemException | UnableToReadFile $exception) {
    // handle the error
}

Dakword\YandexDiskStorage\YandexDiskServiceProvider::class

// config/filesystems.php
'yandex' => [
    'driver' => 'yandex-disk',
    'token' => env('YANDEX_DISK_OAUTH_TOKEN'),
    'prefix' => env('YANDEX_DISK_BASE_PATH', '/'),
    // option => default
    'visibility' => 'private', // 'public', 'private'
    'retain_visibility' => true,
    'checksum_algo' => 'md5', // 'md5', 'sha256'
],

// Usage
// --------------------------------------
$yandexDiskStorage = Storage::disk('yandex');

// create a file
$yandexDiskStorage->put('images/file.jpg', $imageContents);
// check exists
$exists = $yandexDiskStorage->exists('images/file.jpg');