Skip to content
Nico Oelgart edited this page Feb 14, 2015 · 20 revisions

As always, initiate PutIO\API() with the user's access token:

<?php
$accessToken = 'A000000Z'; 
$putio = new PutIO\API($accessToken);

To get a list of files, you do this:

<?php
$parentID = 0; // Optional parent ID
$files = $putio->files->listall($parentID);
print_r($files);
Array
(
    [0] => Array
        (
            [is_shared] => 
            [name] => My file 1.jpg
            [screenshot] => https://put.io/screenshots/xxxxx.jpg
            [created_at] => 2012-09-06T09:28:29
            [parent_id] => 0
            [is_mp4_available] => 
            [content_type] => image/jpeg
            [icon] => https://put.io/thumbnails/xxxxx.jpg
            [id] => 123456789
            [size] => 138765
        )

    [1] => Array
        (
            [is_shared] => 
            [name] => My File 2.jpg
            [screenshot] => https://put.io/screenshots/xxxxx.jpg
            [created_at] => 2012-09-06T08:41:07
            [parent_id] => 0
            [is_mp4_available] => 
            [content_type] => image/jpeg
            [icon] => https://put.io/thumbnails/xxxxx.jpg
            [id] => 123456789
            [size] => 35848
        )
)

Download a file from your account:

<?php
// Extend your execution time if required.
set_time_limit(0);

$fileID = 1234;
$saveAs = 'my-file.mp3';

$response = $putio->files->download($fileID, $saveAs);
var_dump($response);
int(1)

Download the MP4 version of a file from your account:

<?php
// Extend your execution time if required.
set_time_limit(0);

$fileID = 1234;
$saveAs = 'my-file.mp4';

$response = $putio->files->downloadMP4($fileID, $saveAs);
var_dump($response);
int(1)

Upload a file to your account:

<?php
// Extend your execution time if required.
set_time_limit(0);

$file = 'file.jpg';
$folderID = 0; // Optional target folder ID
$response = $putio->files->upload($file, $folderID);

print_r($response);
Array
(
    [is_shared] => 
    [name] => xxxxx.jpg
    [screenshot] => https://put.io/screenshots/xxxxxx.jpg
    [created_at] => 2012-09-01T10:42:04
    [parent_id] => 0
    [is_mp4_available] => 
    [content_type] => image/jpeg
    [icon] => https://put.io/thumbnails/xxxxxxx.jpg
    [id] => 123456789
    [size] => 83909
)

Search for files in your account:

<?php
$query = 'my term';
$page = 1; // Optional page number
$files = $putio->files->search($query, $page);
print_r($files);
?>
Array
(
    [files] => Array
        (
            [0] => Array
                (
                    [name] => My File 1.mp3
                    [screenshot] => 
                    [created_at] => 2012-08-31T20:28:58
                    [parent_id] => 40894510
                    [content_type] => audio/mpeg
                    [owner] => nic0
                    [icon] => https://put.io/images/file_types/audio.png
                    [id] => 123456789
                    [size] => 8304640
                )

            [1] => Array
                (
                    [name] => My File 2.mp3
                    [screenshot] => 
                    [created_at] => 2012-08-31T20:28:57
                    [parent_id] => 40894489
                    [content_type] => audio/mpeg
                    [owner] => nic0
                    [icon] => https://put.io/images/file_types/audio.png
                    [id] => 123456789
                    [size] => 8793168
                )

        )

    [status] => OK
    [next] => http://api.put.io/v2/files/search/my term/page/2
)

Create a new folder:

<?php
$folderName = 'My dir';
$response = $putio->files->makeDir($folderName);
print_r($response);
Array
(
    [is_shared] => 
    [name] => My dir
    [screenshot] => 
    [created_at] => 2012-09-01T10:48:49
    [parent_id] => 0
    [is_mp4_available] => 
    [content_type] => application/x-directory
    [icon] => https://put.io/images/file_types/folder.png
    [id] => 123456789
    [size] => 0
)

Get information about a file or folder

<?php
$fileID = 1234;
$response = $putio->files->info($fileID);

print_r($response);
Array
(
    [is_shared] => 
    [name] => My file.mp3
    [screenshot] => 
    [created_at] => 2012-08-31T20:28:58
    [parent_id] => 40894526
    [is_mp4_available] => 
    [content_type] => audio/mpeg
    [icon] => https://put.io/images/file_types/audio.png
    [id] => 40894527
    [size] => 7135232
)

Delete file from your account:

<?php
$fileID = 123456789;
$response = $putio->files->delete($fileID);
var_dump($response);

// Or delete multiple files at once:
$fileIDs = array(123, 456, 789);
$response = $putio->files->delete($fileIDs);
bool(true)

Rename a file:

<?php
$fileID = 123456789;
$newName = 'New name.jpg';
$response = $putio->files->rename($fileID, $newName);
var_dump($response);
bool(true)

Move one or more files to another folder:

<?php
$fileID = 123456789;
$folderID = 0; // 0 = root dir
$response = $putio->files->move($fileID, $folderID);
var_dump($response);

// Or delete multiple files at once:
$fileIDs = array(123, 456, 789);
$response = $putio->files->move($fileIDs, $folderID);
bool(true)

Convert a video file to MP4

NOTE: The file will be added to the queue, and it may take a few minutes to be done.

<?php
$fileID = 123456789;
$response = $putio->files->convertToMP4($fileID);
var_dump($response);
bool(true)

Get the status of a file in the conversation queue

<?php
$fileID = 123456789;
$response = $putio->files->getMP4Status($fileID);
print_r($response);
Array
(
    [status] => IN_QUEUE
)

Head over to the Friends manager.

Clone this wiki locally