A PHP library to access pCloud API


Table of Contents


System requirements


Get started

Register your application

In order to use this SDK, you have to register your application in My applications.


Install the SDK

Using Composer

Install Composer. Add the following to composer.json file

"require": {
  "pcloud/pcloud-php-sdk": "1.*"
}

Manually

Copy lib/ folder and include lib/pCloud/autoload.php in your code


Initializing the SDK

The SDK uses an OAuth 2.0 access token to authorize requests to the pCloud API. You can obtain a token using the SDK’s authorization flow. To allow the SDK to do that, find App Key, App secret and Redirect URIs in your application configuration page and add them to /example/app.info file.

{
  "appKey": "App key",
  "appSecret": "App secret",
  "redirect_uri": "Redirect URI"
}

Note that redirect_uri is optional.

Run /example/code.php to get an authorization code and use this code in /example/auth.php. This will generate /lib/pCloud/app.cred file with your credentials.


Examples

File examples

Upload a file

<?php

$pCloudFile = new pCloud\File();

$pCloudFile->upload($filePath);

Download a file

<?php

$pCloudFile = new pCloud\File();

$pCloudFile->download($fileId, $destinationFolder);

Folder examples

Create a new folder

<?php

$pCloudFolder = new pCloud\Folder();

$pCloudFolder->create($folderName, $parentId);

List root

<?php

$pCloudFolder = new pCloud\Folder();

$pCloudFolder->listRoot();

Get folder content

<?php

$pCloudFolder = new pCloud\Folder();

$pCloudFolder->getContent($folderId);