PHPackages                             rsd/seafile-php-sdk - 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. rsd/seafile-php-sdk

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

rsd/seafile-php-sdk
===================

This is a PHP package for accessing Seafile Web API

v2.0.1(5y ago)3589.1k↓45.8%18[1 issues](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK/issues)MITPHPPHP &gt;=7.3CI passing

Since Oct 8Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK)[ Packagist](https://packagist.org/packages/rsd/seafile-php-sdk)[ Docs](https://github.com/Schmidt-DevOps/seafile-php-sdk)[ RSS](/packages/rsd-seafile-php-sdk/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (17)Used By (0)

Seafile PHP SDK
===============

[](#seafile-php-sdk)

This is a PHP package for accessing [Seafile Web API](https://download.seafile.com/published/web-api/home.md).

German Web Application Developer Available for Hire!
----------------------------------------------------

[](#german-web-application-developer-available-for-hire)

No marketing skills whatsoever, but low rates, 20+ years of experience, and "german work attitude".

Get in touch now:

[![Unit tests](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK/actions/workflows/tests.yml/badge.svg)](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

What is Seafile?
----------------

[](#what-is-seafile)

- Open Source Cloud Storage for your teams and organizations
- Built in File Encryption, better Protecting your Privacy
- Collaboration around Files, file locking and other features make collaboration easy.

How to get Started
------------------

[](#how-to-get-started)

To get started with Seafile PHP SDK, you may either set up your own private Seafile server (see [https://www.seafile.com/en/product/private\_server/](https://www.seafile.com/en/product/private_server/)) or obtain a cloud account. Because the SDK is in its infancy it's highly recommended to set up a test server or create a test account.

It's not advisable yet to use your real server/account if you already got one.

After you have created your test account continue to the next step.

Roadmap and notes on development
--------------------------------

[](#roadmap-and-notes-on-development)

Please note that this SDK currently is under active development and that things might change rather drastically.

If you are looking for stability please refer to stable tags.

Obtain API token
----------------

[](#obtain-api-token)

Please refer to the [Seafile docs](https://download.seafile.com/published/web-api/home.md#user-content-Quick%20Start) on how to obtain an API token.

This also applies to the token required for functional tests (`TEST_SERVER_AUTHORIZATION_TOKEN`).

Installing Seafile-PHP-SDK
--------------------------

[](#installing-seafile-php-sdk)

The recommended way to install seafile-php-sdk is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

Next, run the Composer command to install the latest stable version of seafile-php-sdk:

```
composer.phar require rsd/seafile-php-sdk
# composer.phar dump-autoload -o # not required anymore
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

You can then later update seafile-php-sdk using Composer:

```
composer.phar update
# composer.phar dump-autoload -o # not required anymore
```

Using Seafile PHP SDK
---------------------

[](#using-seafile-php-sdk)

Hint: Have a look at `bin/example.php` -- everything this SDK can do is covered there!

### Connecting to Seafile

[](#connecting-to-seafile)

First, you need to include the API token (see above):

```
$client = new Client(
    [
        'base_uri' => 'https://your-seafile-server.example.com',
        'debug' => false,
        'headers' => [
            'Authorization' => 'Token ' . $token
        ]
    ]
);
```

### List available libraries

[](#list-available-libraries)

```
$libraryResource = new Library($client);
$libs = $libraryResource->getAll();

foreach ($libs as $lib) {
    printf("Name: %s, ID: %s, is encrypted: %s\n", $lib->name, $lib->id, $lib->encrypted ? 'YES' : 'NO');
}
```

### List directory contents

[](#list-directory-contents)

```
$directoryResource = new Directory($client);
$lib = $libraryResource->getById('some library ID of yours');
$items = $directoryResource->getAll($lib, '/'); // 2nd param is the name of the directory or '/'

foreach ($items as $item) {
    printf("%s: %s (%d bytes)\n", $item->type, $item->name, $item->size);
}
```

### Check if directory item exists

[](#check-if-directory-item-exists)

```
$parentDir = '/'; // DirectoryItem must exist within this directory
$directory = 'DirectoryName';
if($directoryResource->exists($lib, $directoryItemName, $parentDir) === false) {
 //  directory item does not exist
}
```

Be aware that because Seafile Web API does not provide a function to do this check on its own, all items of the directory will get loaded for iteration. So that's not very efficient.

### Create directory

[](#create-directory)

```
$parentDir = '/'; // Create directory within this folder
$directory = 'DirectoryName'; // name of the new Directory
$recursive = false; // recursive will create parentDir if not already existing
$success = $directoryResource->create($lib, $directory, $parentDir, $recursive);
```

### Download file from unencrypted library

[](#download-file-from-unencrypted-library)

```
$dir = '/'; // dir in the library
$saveTo = '/tmp/'. $item->name; // save file to this local path
$fileResource = new File($client);
$downloadResponse = $fileResource->downloadFromDir($lib, $item, $saveTo, $dir);
```

### Download file from encrypted library

[](#download-file-from-encrypted-library)

Trying to download a file from an encrypted library without unlocking it first would inevitably fail, so just unlock (API docs say "decrypt") the library before attempting:

```
$success = $libraryResource->decrypt($libId, ['query' => ['password' => $password]]);
// rest is the same as 'Download file from unencrypted library', see above
```

### Upload file

[](#upload-file)

```
$fileToUpload = '/path/to/file/to/be/uploaded.zip';
$dir = '/'; // directory in the library to save the file in
$response = $fileResource->upload($lib, $fileToUpload, $dir);
$uploadedFileId = (string)$response->getBody();
```

### Update file

[](#update-file)

```
$response = $fileResource->update($lib, $newFilename, '/');
$updatedFileId = (string)$response->getBody();
```

### Get file details

[](#get-file-details)

```
$directoryItem = $fileResource->getFileDetail($lib, '/' . basename($fullFilePath));
```

### Get API user account info

[](#get-api-user-account-info)

```
$accountResource = new Account($client);

$accountType = $accountResource->getInfo();

print_r($accountType->toArray());
```

### Get all accounts

[](#get-all-accounts)

```
$accountResource = new Account($client);

$accountTypes = $accountResource->getAll();

foreach ($accountTypes as $accountType) {
    print_r($accountType->toArray());
}
```

### Create account

[](#create-account)

```
$newAccountType = (new AccountType)->fromArray([
    'email' => 'someone@example.com',
    'password' => 'password',
    'name' => 'Hugh Jazz',
    'note' => 'I will not waste chalk',
    'institution' => 'Duff Beer Inc.'
]);

$success = $accountResource->create($newAccountType);
```

### Update account

[](#update-account)

```
$updateAccountType = (new AccountType)->fromArray([
    'name' => 'Divine Hugh Jazz',
    'email' => 'someone@example.com'
]);

$success = $accountResource->update($updateAccountType);
```

### Get account info by email address

[](#get-account-info-by-email-address)

```
$accountResource = new Account($client);

$accountType = $accountResource->getByEmail('someone@example.com');

print_r($accountType->toArray());
```

### Delete account

[](#delete-account)

```
$accountResource = new Account($client);

$accountType = (new AccountType)->fromArray([
    'email' => 'someone@example.com'
]);

$success = $accountResource->remove($accountType);
```

or

```
$accountResource = new Account($client);

$success = $accountResource->removeByEmail('someone@example.com');
```

### Get avatar of an account

[](#get-avatar-of-an-account)

```
$accountType = (new AccountType)->fromArray([
   'email' => 'someone@example.com'
]);

$avatarResource = new Avatar($client);

print_r($avatarResource->getUserAvatar($accountType)->toArray());
```

or

```
print_r($avatarResource->getUserAvatarByEmail('someone@example.com')->toArray());
```

### Create and remove shared link

[](#create-and-remove-shared-link)

```
$libraryResource = new Library($client);
$directoryResource = new Directory($client);
$fileResource = new File($client);
$shareLinkResource = new ShareLinks($client);

// create share link for a file
$expire = 5;
$p = "/" . basename($newFilename);
$password = 'qwertz123';

$defaultPermissions = new SharedLinkPermissions(SharedLinkPermissions::CAN_DOWNLOAD);
$extendedPermissions = new SharedLinkPermissions(SharedLinkPermissions::CAN_DOWNLOAD | SharedLinkPermissions::CAN_EDIT);

$shareLinkType = $shareLinkResource->create($lib, $p, $defaultPermissions, $expire, $password);

// remove shared link
$success = $shareLinkResource->remove($shareLinkType);
```

### Get all starred files, star and unstar file

[](#get-all-starred-files-star-and-unstar-file)

```
$libraryResource = new Library($client);
$starredFileResource = new StarredFile($client);

// get all starred files
$dirItems = $starredFileResource->getAll();

// unstar all starred files
foreach ($dirItems as $dirItem) {
    $lib = $libraryResource->getById($dirItem->repo);
    $starredFileResource->unstar($lib, $dirItem);
}

// re-star all files
foreach ($dirItems as $dirItem) {
    $lib = $libraryResource->getById($dirItem->repo);
    $starredFileResource->star($lib, $dirItem);
}
```

### Debugging and how to enable logging of requests and responses

[](#debugging-and-how-to-enable-logging-of-requests-and-responses)

This example requires monolog. Log entries and Guzzle debug info will be written to stdout.

```
$logger = new Logger('Logger');

$stack = HandlerStack::create();
$stack->push(
    Middleware::log(
        $logger,
        new MessageFormatter("{hostname} {req_header_Authorization} - {req_header_User-Agent} - [{date_common_log}] \"{method} {host}{target} HTTP/{version}\" {code} {res_header_Content-Length} req_body: {req_body} response_body: {res_body}")
    )
);

$client = new Client(
    [
        'base_uri' => 'https://your-seafile-server.example.com',
        'debug' => true,
        'handler' => $stack,
        'headers' => [
            'Authorization' => 'Token ' . $token
        ]
    ]
);
```

Issues
------

[](#issues)

- `File::upload()`: Parameter `$newFilename` actually does not set a new file name when uploading a file (thanks to )

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

[](#dependencies)

- PHP &gt;=8.0 64 bits
- Guzzle 7.2

Seafile Web API Support Matrix
------------------------------

[](#seafile-web-api-support-matrix)

ResourceWeb API VersionSupport gradeAccountv2★★★☆Avatarv2.1★★★★Eventsv2Yet to be done, [contact me](mailto:rene+_gth@sdo.sh)File Share Linkv2.1★★★☆Groupv2★☆☆☆Library/Directoryv2★★☆☆Library/Filev2★★☆☆Library/Libraryv2★★☆☆Library/Multiple Filesv2★★★★Organizationv2Yet to be done, [contact me](mailto:rene+_gth@sdo.sh)Starred Filesv2★★★★Seafile server compatibility
----------------------------

[](#seafile-server-compatibility)

Tested with:

- Seafile Server 5.1.3 for generic Linux/Debian Jessie
- Seafile Server 5.1.3 for generic Linux/Debian Wheezy
- Seafile Server 5.1.4 for generic Linux/Ubuntu Xenial
- Seafile Server 6.0.3 for generic Linux/Ubuntu Xenial
- Seafile Server 7.x+ for Ubuntu 20.04 LTS

Support
-------

[](#support)

I'd be happy to implement new features for you at a competitive hourly rate. Get in touch now:

Contributing
------------

[](#contributing)

Please note that this package still is in its infancy. Only a part of the API has been implemented so far.

**Pull requests are welcome**. Please adhere to some very basic and simple principles:

- Follow "separation of concern" on all levels: 1 issue == 1 pull request. Do not cover multiple issues in a pull request.
- Unit tests raise the chance of your pull request getting accepted.
- The same goes for [PHPDoc](https://en.wikipedia.org/wiki/PHPDoc) blocks.

Tests
-----

[](#tests)

There are two types of tests:

1. Unit tests that test a code unit without external dependencies and no data manipulation. Please always provide at least unit tests when contributing.
2. Functional tests that run against a live server instance (=may have external dependencies) and also alter data. Disabled and thus skipped by default. Please refer to `/phpunit/php` in `phpunit.xml.dist` for information on how to enable functional tests.

Links
-----

[](#links)

-
- [https://download.seafile.com/published/seafile-manual/develop/web\_api\_v2.1.md](https://download.seafile.com/published/seafile-manual/develop/web_api_v2.1.md)
-
-  (Seafile server hosting in Germany)
-  (Seafile server hosting in Germany)

License
-------

[](#license)

[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2023 Rene Schmidt DevOps UG (haftungsbeschränkt) &amp; Co. KG

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance48

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 82.3% 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 ~236 days

Recently: every ~471 days

Total

9

Last Release

1988d ago

Major Versions

v0.0.5 → v1.0.02016-01-16

v1.0.1 → v2.0.02020-11-30

PHP version history (2 changes)0.0.1PHP &gt;=5.5

v2.0.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a9df3d95a655a4e58121e77ba7cf91da1fdb6c0ed4ebbc8371998df7ef9708c?d=identicon)[sdo.sh](/maintainers/sdo.sh)

---

Top Contributors

[![rene-s](https://avatars.githubusercontent.com/u/1558400?v=4)](https://github.com/rene-s "rene-s (116 commits)")[![h44z](https://avatars.githubusercontent.com/u/1370804?v=4)](https://github.com/h44z "h44z (14 commits)")[![steffi-s](https://avatars.githubusercontent.com/u/4881402?v=4)](https://github.com/steffi-s "steffi-s (3 commits)")[![swarnat](https://avatars.githubusercontent.com/u/1639540?v=4)](https://github.com/swarnat "swarnat (3 commits)")[![Sevavietl](https://avatars.githubusercontent.com/u/1844827?v=4)](https://github.com/Sevavietl "Sevavietl (1 commits)")[![nibsirahsieu](https://avatars.githubusercontent.com/u/208039?v=4)](https://github.com/nibsirahsieu "nibsirahsieu (1 commits)")[![decadence](https://avatars.githubusercontent.com/u/1434668?v=4)](https://github.com/decadence "decadence (1 commits)")[![fzyzcjy](https://avatars.githubusercontent.com/u/5236035?v=4)](https://github.com/fzyzcjy "fzyzcjy (1 commits)")[![dakira](https://avatars.githubusercontent.com/u/576555?v=4)](https://github.com/dakira "dakira (1 commits)")

---

Tags

apicollaborationphpseafileseafile-php-sdkseafile-serverphpsdkcloudstoragecollaborationencryptedseafile

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/rsd-seafile-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/rsd-seafile-php-sdk/health.svg)](https://phpackages.com/packages/rsd-seafile-php-sdk)
```

###  Alternatives

[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[qiniu/php-sdk

Qiniu Resource (Cloud) Storage SDK for PHP

8483.0M240](/packages/qiniu-php-sdk)[microsoft/azure-storage-common

This project provides a set of common code shared by Azure Storage Blob, Table, Queue and File PHP client libraries.

4316.8M6](/packages/microsoft-azure-storage-common)[azure-oss/storage

Azure Blob Storage PHP SDK

37985.0k5](/packages/azure-oss-storage)[itbdw/laravel-storage-qiniu

A storage library for laravel5 and qiniu sdk

7015.2k](/packages/itbdw-laravel-storage-qiniu)

PHPackages © 2026

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