PHP code example of mathsgod / pcloud-sdk-php

1. Go to this page and download the library: Download mathsgod/pcloud-sdk-php 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/ */

    

mathsgod / pcloud-sdk-php example snippets


$access_token = 'YOUR_TOKEN';
$client = new \GuzzleHttp\Client([
    'base_uri' => "https://eapi.pcloud.com/", 
    'headers' => [
        'Authorization' => 'Bearer ' . $access_token,
    ],
]);

$api = new \pCloud\Sdk\Api($client);

// Single file
$result = $api->uploadfile([
    '/path/to/local/file.jpg'
], null, 0); // Upload to root folder

// Multiple files (custom filenames)
$result = $api->uploadfile([
    ['path' => '/tmp/a.jpg', 'filename' => 'photo1.jpg'],
    ['path' => '/tmp/b.png', 'filename' => 'photo2.png'],
], null, 123456); // Upload to folderid=123456

// By fileid
$meta = $api->stat(123456789);
// By path
$meta = $api->stat(null, '/Documents/test.pdf');

$link = $api->getfilelink(123456789);
echo $link['hosts'][0] . $link['path'];

$api->deletefile(123456789);
// or
$api->deletefile(null, '/Documents/test.pdf');

// By folderid+name
$meta = $api->createfolder(null, 123456, 'New Folder');
// By full path
$meta = $api->createfolder('/Documents/New Folder');

$list = $api->listfolder(null, 123456); // By folderid
$list = $api->listfolder('/Documents'); // By path

$api->deletefolderrecursive(123456); // Deletes all contents, use with caution

// Copy to another folder
$api->copyfolder(123456, null, 654321);
// Copy to a specific path
$api->copyfolder(123456, null, null, '/Documents/Backup/');

// Copy file to new folder
$api->copyfile(123, null, 456, null, 'newname.jpg');
// Move and rename
$api->renamefile(123, null, null, 456, 'newname.jpg');

$hash = $api->checksumfile(123456789);
echo $hash['sha1'];

$thumb = $api->getthumblink(123456789, null, '200x200');
echo $thumb['hosts'][0] . $thumb['path'];
bash
composer