PHP code example of minhyung / flysystem-mybox

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

    

minhyung / flysystem-mybox example snippets


use League\Flysystem\Filesystem;
use Minhyung\Flysystem\Mybox\MyboxAdapter;
use Minhyung\Mybox\MyboxClient;

$filesystem = new Filesystem(new MyboxAdapter(MyboxClient::create($_ENV['MYBOX_PAT'])));

$filesystem->write('reports/2026-08.csv', $csv);
echo $filesystem->read('reports/2026-08.csv');

$adapter = new MyboxAdapter($client, 'app-data/uploads');

use Minhyung\Flysystem\Mybox\Enum\DeletionMode;
use Minhyung\Flysystem\Mybox\MyboxAdapterOptions;

$adapter = new MyboxAdapter($client, options: new MyboxAdapterOptions(
    deletionMode: DeletionMode::Purge,
    visibility: League\Flysystem\Visibility::PUBLIC,
));

$filesystem->writeStream('video.mp4', $stream, ['size' => $lengthInBytes]);

$url = $filesystem->temporaryUrl('reports/2026-08.csv', new DateTimeImmutable('+5 minutes'));

use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Minhyung\Flysystem\Mybox\MyboxAdapter;
use Minhyung\Mybox\MyboxClient;

Storage::extend('mybox', function (array $app, array $config) {
    $adapter = new MyboxAdapter(MyboxClient::create($config['token']), $config['root'] ?? '');

    return new \Illuminate\Filesystem\FilesystemAdapter(new Filesystem($adapter), $adapter, $config);
});

// config/filesystems.php
'mybox' => [
    'driver' => 'mybox',
    'token' => env('MYBOX_PAT'),
    'root' => env('MYBOX_ROOT', ''),
],

$filesystem->fileExists('reports/2026-08.csv');   // walks: 2 requests
$filesystem->fileSize('reports/2026-08.csv');     // 0 requests
$filesystem->lastModified('reports/2026-08.csv'); // 0 requests
$filesystem->mimeType('reports/2026-08.csv');     // 0 requests
$filesystem->fileExists('reports/2026-07.csv');   // 0 requests