PHP code example of ulrack / vfs

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

    

ulrack / vfs example snippets


use Ulrack\Vfs\Driver\LocalFileSystemDriver;

$driver = new LocalFileSystemDriver();

$fileSystem = $driver->connect(__DIR__ . '/tests/test-filesystem');

use Ulrack\Vfs\FileSystem\LocalFileSystem;

$filesystem = new LocalFileSystem(__DIR__ . '/tests/test-filesystem');

use Ulrack\Vfs\Common\FileInterface;
use Ulrack\Vfs\File\File;

$fileResource = fopen(__DIR__ . '/tests/test-filesystem/foo.txt');
$fileIterable = new File($fileResource, FileInterface::MODE_LINE);

// Write foo to the second line.
$fileIterable[1] = 'foo';

// Outputs foo
echo $fileIterable[1];

// Removes foo from the file.
unset($fileIterable[1]);

// Appends foo as a line to the end of the file.
$fileIterable[] = 'foo';

// Will output the line and line number for every line in the file.
foreach ($fileIterable as $key => $line) {
    echo sprintf('Line %d says: %s', $key + 1, $line);
}