PHPackages                             impressiveweb/yandex-disk - 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. [API Development](/categories/api)
4. /
5. impressiveweb/yandex-disk

ActiveLibrary[API Development](/categories/api)

impressiveweb/yandex-disk
=========================

Simple implementation of Yandex Disk API

1.0.6(2y ago)03431MITPHPPHP ^8.1

Since Apr 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/pavel-macovschi/yandex-disk)[ Packagist](https://packagist.org/packages/impressiveweb/yandex-disk)[ Docs](https://github.com/pavel-macovschi/yandex-disk-api)[ RSS](/packages/impressiveweb-yandex-disk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (8)Used By (1)

Simple implementation of Yandex Disk API
========================================

[](#simple-implementation-of-yandex-disk-api)

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

[](#installation)

Package installation via composer:

```
composer require impressiveweb/yandex-disk
```

Usage
-----

[](#usage)

### Go to  and click on a button to get OAuth token.

[](#go-to-httpsyandexrudevdiskpoligon-and-click-on-a-button-to-get-oauth-token)

```
use ImpressiveWeb\YandexDisk\Client;
// Access token.
$accessToken = 'xxxxxxxxxxxxxxxxxxx';

// Client init with an access token and default path prefix to a whole disk:/.
$client = new Client($accessToken);
```

### Go to  create your first App and add necessary permissions.

[](#go-to-httpsoauthyandexruclientnew-create-your-first-app-and-add-necessary-permissions)

### After getting client\_id and client\_secret you can use it for a client initialization.

[](#after-getting-client_id-and-client_secret-you-can-use-it-for-a-client-initialization)

```
// Auth credentials.
$credentials = [
    'client_id' => 'xxxxxxxxxxxxxxxxxxx',
    'client_secret' => 'xxxxxxxxxxxxxxxxxxx',
];

// Client init with credentials and access to the whole disk.
// Default value for path prefix is set to disk:/.
$client = new Client($credentials);

// If you create you first APP, use path of your APP.
$pathPrefix = 'disk:/Applications/YourApp'

// Client init with credentials and access to your Application.
$client = new Client($credentials, $pathPrefix);

// Create and proceed an auth url to get a code.
$authUrl = $client->getAuthUrl([
    'redirect_uri' => 'https://your-domain-app'
    // ...other options
]);

// After redirecting to your project domain use code from a query.
// https://your-app?code=xxxxxx

// Code that is taken from a query.
$code = 'xxxxxx'

// Make a request to get an access and a refresh token.
$reply = $client->authCodeAndGetToken($code);

// Reply data.
array:4 [▼
  "access_token" => "xx_xxxXXxxxAAAABWGbHaAAqjUwAAAADvXc-xxxxxxxxxxxxxxxxxxxx"
  "expires_in" => 25137530
  "refresh_token" => "1:xxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxx-xxxxxxxxxxxx"
  "token_type" => "bearer"
]

// If reply has been successful you've got both tokens.
$accessToken = $reply['access_token'];

// Save a refresh token somewhere in a secret place.
$refreshToken = $reply['refresh_token'];

// Refresh token should be set to make sure an automatic access token update.
$client->setRefreshToken($refreshToken);
```

Here are several examples of API usage.
=======================================

[](#here-are-several-examples-of-api-usage)

### Get a disk meta information.

[](#get-a-disk-meta-information)

```
// Get a disk meta information.
$reply = $client->discInfo();

// Reply data.
array:11 [▼
  "max_file_size" => 1073741824
  "paid_max_file_size" => 53687091200
  "total_space" => 10737418240
  "reg_time" => "2021-06-29T10:20:40+00:00"
  "trash_size" => 165164170
  "is_paid" => false
  "used_space" => 3342277118
  "system_folders" => array:15 [▶]
  "user" => array:6 [▶]
  "unlimited_autoupload_enabled" => false
  "revision" => 1711829122396623
]

// Get a disk meta information with a list of attributes to be returned.
$reply = $client->discInfo(['max_file_size', 'paid_max_file_size', 'total_space']);

// Reply data.
array:3 [▼
  "max_file_size" => 1073741824
  "paid_max_file_size" => 53687091200
  "total_space" => 10737418240
]
```

### Get all contents with metadata information.

[](#get-all-contents-with-metadata-information)

```
// If a path is not set a path prefix will be used as a root directory.
$reply = $client->listContent();

// Reply data.
array:10 [▼
  "_embedded" => array:6 [▶]
  "name" => "disk"
  "exif" => []
  "resource_id" => "1444524506:144a2c7976ad2f6f60317baa505447af1dee1fbb4a13f4dccab8bb252846d6ee"
  "created" => "2012-04-04T20:00:00+00:00"
  "modified" => "2012-04-04T20:00:00+00:00"
  "path" => "disk:/"
  "comment_ids" => []
  "type" => "dir"
  "revision" => 1624962040946659
]

// There is a default limit for 20 items per one request when you read catalogues.
// You can increase a default amount of items on a Client initialization step.
$client = new Client(itemsLimit: 100);

// Since php 8.0 you can use named arguments and skip a lot of default arguments.

// Get a list of items for a root directory using selected fields.
$reply = $client->listContent(fields: ['_embedded.items.path']);

// Reply data.
array:1 [▼
  "_embedded" => array:1 [▼
    "items" => array:2 [▼
      0 => array:1 [▼
        "path" => "disk:/Applications"
      ]
      1 => array:1 [▼
        "path" => "disk:/Downloads"
      ]
      // Other items.
      [...]
    ]
  ]
]

// Get a list of items by a path with 200 items limit.
$limit = 200;
$path = 'path/to/resource';

// Returns 100 items using a specified path.
$client->listContent($path, limit: $limit);

// Returns 100 items that are sorted by size using a specified path.
$client->listContent($path, limit: $limit, sort: 'size');

// Returns items using a specified path recursively.
// Amount of all items in this case depends on subdirectories you have in a path.
$client->listContent($path, limit: $limit, deep: true);
```

### Work with directories.

[](#work-with-directories)

```
$path = 'path/to/created/dir';
$from = 'from/path';
$to = 'to/path';

// Add a new folder.
$client->addDirectory($path);

// Copy a file or a folder.
$client->copy($from, $to);

// Move a file or a folder to a different location.
$client->move($from, $to);

// Delete a folder or a file at a given path.
$client->remove($path);
```

### Download resources.

[](#download-resources)

```
// 1. Get a download url.
$path = 'path/to/existing/resource/on/disk';
$reply = $client->getDownloadUrl($path, ['href']);

// Reply data.
array:1 [▼
  "href" => "https://downloader.disk.yandex.ru/disk/8caa900296bd8b8daa64b36c870d9[...]"
]

// 2. Depends on an application requirements you can get a link and download a resource directly via GET method.
$link = $reply['href'];

// 2. Or open a stream and use it for your own needs.
$stream = $client->getStream($link);
```

### Upload resources.

[](#upload-resources)

```
// 1. Get an upload url.
$path = 'path/to/where/resource/will/be/placed/on/disk';
$reply = $client->getUploadUrl($path);

// Reply data.
array:4 [▼
  "operation_id" => "d97f66b1638b1438825ed6d5a5433eb15f95bd5298[...]"
  "href" => "https://uploader54j.disk.yandex.net:443/upload-target/20240403T140247[...]"
  "method" => "PUT"
  "templated" => false
]
// If href in reply data will not be requested for 30 minutes it won't be available for uploading, and you need to create another one.

// 2. Use href however you want.

// 3. Or use an upload method to upload file using getStream helper.
$name = 'picture.jpg';
$fromPath = __DIR__.DIRECTORY_SEPARATOR.$name;
$toPath = "path/on/disk/$name";
// Open a stream.
$stream = $client->getStream($fromPath, 'r+');
// Upload file.
$client->upload($toPath, $stream);
```

### Work with a Trash.

[](#work-with-a-trash)

```
$path = 'path/to/trash/resource';

// Listing a trash content.
$client->trashListContent();

// Listing a trash content in a specified path.
$client->trashListContent($path);

// Restore a specified resource from a trash.
$client->trashContentRestore($path);

// Remove a resource from a basket.
$client->trashContentDelete($path);

// Clear the whole trash.
$client->trashClear();
```

### Some other methods are self-descriptive and easy to understand because the most of them are similar to an original Yandex Disk API.

[](#some-other-methods-are-self-descriptive-and-easy-to-understand-because-the-most-of-them-are-similar-to-an-original-yandex-disk-api)

### Read an official API documentation  to get more details how to use methods and its arguments.

[](#read-an-official-api-documentation-httpsyandexrudevdisk-apidocru-to-get-more-details-how-to-use-methods-and-its-arguments)

If you need to use a common interface among different filesystems you can use Flysystem:
===================================================================================================================================

[](#if-you-need-to-use-a-common-interface-among-different-filesystems-you-can-use-flysystem-httpsflysystemthephpleaguecomdocs)

This Flysystem Adapter:  is fully compatible with this version of Yandex Disk API.
------------------------------------------------------------------------------------------------------------------------------------------------------

[](#this-flysystem-adapter-httpspackagistorgpackagesimpressivewebyandex-disk-flysystem-is-fully-compatible-with-this-version-of-yandex-disk-api)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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

Total

7

Last Release

763d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/999769c635c3ed1d860d33d568f45f6fcfb9476d0943b298dadc742380296c91?d=identicon)[pavel-macovschi](/maintainers/pavel-macovschi)

---

Top Contributors

[![pavel-macovschi](https://avatars.githubusercontent.com/u/68183611?v=4)](https://github.com/pavel-macovschi "pavel-macovschi (43 commits)")

---

Tags

apiyandexyandex diskyandex cloudimpressivewebyandex disk api

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/impressiveweb-yandex-disk/health.svg)

```
[![Health](https://phpackages.com/badges/impressiveweb-yandex-disk/health.svg)](https://phpackages.com/packages/impressiveweb-yandex-disk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[get-stream/stream-chat

A PHP client for Stream Chat (https://getstream.io/chat/)

301.8M2](/packages/get-stream-stream-chat)[leonied7/yandex-disk-api

Библиотека для работы с Яндекс.диск API

152.2k](/packages/leonied7-yandex-disk-api)[hardworm/webmaster.api

Yandex Webmaster Api v4.1 library

109.7k](/packages/hardworm-webmasterapi)

PHPackages © 2026

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