PHPackages                             pcloud/pcloud-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. [API Development](/categories/api)
4. /
5. pcloud/pcloud-php-sdk

ActiveLibrary[API Development](/categories/api)

pcloud/pcloud-php-sdk
=====================

pCloud SDK for PHP

3.0.0(3y ago)6511.6k—0%25[3 issues](https://github.com/pCloud/pcloud-sdk-php/issues)[1 PRs](https://github.com/pCloud/pcloud-sdk-php/pulls)1MITPHPPHP &gt;=7.1

Since Jan 6Pushed 2y ago5 watchersCompare

[ Source](https://github.com/pCloud/pcloud-sdk-php)[ Packagist](https://packagist.org/packages/pcloud/pcloud-php-sdk)[ RSS](/packages/pcloud-pcloud-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (1)

pCloud SDK for PHP
==================

[](#pcloud-sdk-for-php)

A PHP library to access [pCloud API](https://docs.pcloud.com/)

---

Table of Contents
-----------------

[](#table-of-contents)

- [System requirements](#system-requirements)
- [Get started](#get-started)
    - [Register your application](#register-your-application)
- [Install the SDK](#install-the-sdk)
    - [Using Composer](#using-composer)
    - [Manually](#manually)
- [Initializing the SDK](#initializing-the-sdk)
- [Example](#example)
- [Migration guide](#migration-guide)

---

System requirements
===================

[](#system-requirements)

### PHP 7.1.0 or higher is Required

[](#php-710-or-higher-is-required)

```
Likelihood Of Impact: Critical

```

- The new minimum PHP version is now 7.1.0.
- PHP [cURL extension](http://php.net/manual/en/curl.setup.php)

---

Get started
-----------

[](#get-started)

### Register your application

[](#register-your-application)

In order to use this SDK, you have to register your application in [My applications](https://docs.pcloud.com).

---

Install the SDK
---------------

[](#install-the-sdk)

### Using Composer

[](#using-composer)

Install [Composer](http://getcomposer.org/download/).

```
$ composer require pcloud/pcloud-php-sdk
```

or add the following to `composer.json` file

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

```

### Manually

[](#manually)

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

---

Initializing the SDK
--------------------

[](#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/code.php` and `/example/auth.php`.

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 return `access_token` and `locationid`.

---

Example
-------

[](#example)

```
// Include autoload.php and set the credential file path

$access_token = "ACCESS_TOKEN";
$locationid = 1;

$pCloudApp = new pCloud\Sdk\App();
$pCloudApp->setAccessToken($access_token);
$pCloudApp->setLocationId($locationid);

// Create Folder instance

$pcloudFolder = new pCloud\Sdk\Folder($pCloudApp);

// Create new folder in root

$folderId = $pcloudFolder->create("New folder");

// Create File instance

$pcloudFile = new pCloud\Sdk\File($pCloudApp);

// Upload new file in created folder

$fileMetadata = $pcloudFile->upload("./sample.png", $folderId);

// Get folder content

$folderContent = $pcloudFolder->getContent($folderId);

```

### Creating custom requests

[](#creating-custom-requests)

```
$access_token = "";
$locationid = 1;

$pCloudApp = new pCloud\Sdk\App();
$pCloudApp->setAccessToken($access_token);
$pCloudApp->setLocationId($locationid);

$method = "userinfo";
$params = array();

$request = new pCloud\Sdk\Request($pCloudApp);
$response = $request->get($method, $params); // the second argument is optional

```

Migration guide
---------------

[](#migration-guide)

In version SDK version 3 the most significant changes are related to adjusting the namespaces. To easily migrate to version 3 you need to change the following:

```
