PHP code example of appitudeio / lcms-storage

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

    

appitudeio / lcms-storage example snippets




CMS\Storage;

// Initialize client
$storage = new Storage('your-domain.com', 'your_api_key');

// Upload a file
$response = $storage->upload('/path/to/local/image.jpg', '/uploads/image.jpg');
echo "Uploaded to: " . $response->url['asset'];

// List directory contents
$listing = $storage->list('/uploads');
foreach ($listing->items as $item) {
    echo $item['key'] . " - " . $item['url'] . "\n";
}

// Delete file
$storage->delete('/uploads/old-image.jpg');

$storage = new LCMS\Storage\Storage(string $domain, string $apiKey);

upload(string $filePath, string $remotePath): UploadResponse

$response = $storage->upload('/tmp/photo.jpg', '/gallery/photo.jpg');
if ($response->success) {
    echo "Uploaded: " . $response->url['asset'];
}

delete(string $path): void

$storage->delete('/gallery/old-photo.jpg');

list(string $path = ''): ListResponse

$listing = $storage->list('/gallery');

foreach ($listing->items as $item) {
    echo $item['key'] . " - " . $item['size'] . " bytes\n";
}

foreach ($listing->prefixes as $prefix) {
    echo "Subdirectory: " . $prefix . "\n";
}

try {
    $response = $storage->upload('/path/to/file.jpg', '/uploads/file.jpg');
    if ($response->success) {
        echo "Success: " . $response->url['asset'];
    } else {
        echo "Upload failed: " . $response->message;
    }
} catch (\InvalidArgumentException $e) {
    echo "Validation error: " . $e->getMessage();
} catch (\RuntimeException $e) {
    echo "Upload failed: " . $e->getMessage();
}