PHP code example of fluxsave / sdk

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

    

fluxsave / sdk example snippets


use VaultSens\VaultSensClient;

$client = new VaultSensClient(
    'https://api.vaultsens.com',
    'your-api-key',
    'your-api-secret'
);

$result = $client->uploadFile('./photo.png', 'hero', 'low', null, 'photo.png', 'image/png');
echo $result['data']['_id'];  // file ID
echo $result['data']['url'];  // public URL

$result = $client->uploadFile(
    './photo.png',
    'my-image',   // optional display name stored with the file
    'medium',     // optional compression level applied server-side
    'folder-id',  // optional folder to place the file in
    'photo.png',  // optional multipart filename sent to VaultSens
    'image/png'   // optional explicit MIME type
);

$result = $client->uploadFiles(
    ['./a.png', './b.jpg'],
    null,
    'low',
    'folder-id',
    ['a.png', 'b.jpg'],
    ['image/png', 'image/jpeg']
);

$all     = $client->listFiles();
$inDir   = $client->listFiles('folder-id');
$atRoot  = $client->listFiles('root');

$meta = $client->getFileMetadata('file-id');

$client->updateFile('file-id', './new-photo.png', null, 'high', 'new-photo.png', 'image/png');

$client->deleteFile('file-id');

$url = $client->buildFileUrl('file-id', [
    'width'   => 800,
    'height'  => 600,
    'format'  => 'webp',
    'quality' => 80,
]);

$result  = $client->listFolders();
$folders = $result['data'];

$result   = $client->createFolder('Marketing');
$folderId = $result['data']['_id'];

// nested folder
$client->createFolder('2024', $folderId);

$client->renameFolder('folder-id', 'New Name');

$client->deleteFolder('folder-id');

$result = $client->getMetrics();
$data   = $result['data'];
// $data['totalFiles'], $data['totalStorageBytes'], $data['storageUsedPercent'], ...

use VaultSens\VaultSensError;

try {
    $client->uploadFile('./photo.png');
} catch (VaultSensError $e) {
    echo $e->getMessage();   // human-readable message
    echo $e->getCode();      // HTTP status code
    echo $e->errorCode;      // machine-readable error code

    switch ($e->errorCode) {
        case VaultSensError::FILE_TOO_LARGE:
            echo 'File exceeds your plan limit';
            break;
        case VaultSensError::STORAGE_LIMIT:
            echo 'Storage quota exceeded';
            break;
        case VaultSensError::MIME_TYPE_NOT_ALLOWED:
            echo 'File type not allowed on your plan';
            break;
        case VaultSensError::COMPRESSION_NOT_ALLOWED:
            echo 'Compression level not permitted on your plan';
            break;
        case VaultSensError::FILE_COUNT_LIMIT:
            echo 'File count limit reached';
            break;
        case VaultSensError::FOLDER_COUNT_LIMIT:
            echo 'Folder count limit reached';
            break;
        case VaultSensError::SUBSCRIPTION_INACTIVE:
            echo 'Subscription is not active';
            break;
    }
}