PHP code example of tinycdn / cdn-api

1. Go to this page and download the library: Download tinycdn/cdn-api 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/ */

    

tinycdn / cdn-api example snippets




$cdn = new \Tinycdn\CdnApi('your-api-token');

try {
    
    ////////////
    // Upload //
    ////////////

    // simple upload
    $data1 = $cdn->upload('path/to/file.ext');
    var_dump($data1);

    // more options
    $params = [
        'is_public' => false,        // default true
        'type'      => 'image',      // default file
        'filename'  => 'my-img.jpg', // if not set, filename will be detected automatically
        'rule_key'  => 'my-rule',    // see docs for details
        'folder_id' => 555,          // 0 - root folder. See more about folders
    ];
    $data2 = $cdn->upload('https://images.local/image.jpg', $params);
    var_dump($data2);

    /////////////
    // Folders //
    /////////////

    $filters = [
        'title' => 'Avatars',
        'idp'   => 0,
    ];
    $list = $cdn->getFoldersList($filters);
    $folder = $list[0] ?? $cdn->addFolder('Avatars');

    var_dump($folder);
    
} catch (Exception $e) {
    echo $e->getMessage();
}