PHP code example of ajgl / flysystem-cow

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

    

ajgl / flysystem-cow example snippets




jgl\Flysystem\Cow\CowFilesystemAdapter;
use League\Flysystem\Config;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;

// Base adapter (read-only)
$baseAdapter = new InMemoryFilesystemAdapter();
$baseAdapter->write('example.txt', 'Hello, World!', new Config());

// Optional top adapter (write layer)
$topAdapter = new InMemoryFilesystemAdapter();

// Create the COW adapter
$cowAdapter = new CowFilesystemAdapter($baseAdapter, $topAdapter);

// Base file overwriting
$cowAdapter->write('example.txt', 'Hello, Planet!', new Config());
echo $cowAdapter->read('example.txt'); // Outputs: Hello, Planet!
echo PHP_EOL;

echo $baseAdapter->read('example.txt'); // Outputs: Hello, World!
echo PHP_EOL;

echo $topAdapter->read('example.txt'); // Outputs: Hello, Planet!
echo PHP_EOL;

// Base file deletion
$cowAdapter->delete('example.txt');
echo $cowAdapter->fileExists('example.txt') ? 'Yes' : 'No'; //Outputs: No
echo PHP_EOL;

echo $baseAdapter->fileExists('example.txt') ? 'Yes' : 'No'; //Outputs: Yes
echo PHP_EOL;

echo $topAdapter->fileExists('example.txt') ? 'Yes' : 'No'; //Outputs: No
echo PHP_EOL;