PHP code example of contenir / storage

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

    

contenir / storage example snippets


use Contenir\Storage\StorageManager;
use Contenir\Storage\Adapter\LocalFilesystem;
use Contenir\Storage\VariantRegistry;

$variants = new VariantRegistry();
$variants->register('admin-thumb', new Variant(width: 200, height: 200));

$manager = new StorageManager();
$manager->register('default', new LocalFilesystem(
    rootPath: '/var/www/uploads',
    publicUrl: 'https://example.com/uploads',
    variants: $variants,
));

$backend = $manager->get('default');
$url = $backend->url('logos/site.png', variant: 'admin-thumb');

// Convenience for the canonical admin-thumbnail variant. Returns null
// when the profile doesn't declare it or the asset hasn't been
// materialised yet — CMS UIs can call this on any profile and fall back
// to whatever URL they have on hand.
$thumb = $backend->thumbnailUrl('logos/site.png');