PHP code example of ddruganov / php-transactional-filesystem

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

    

ddruganov / php-transactional-filesystem example snippets



$folder = '/opt/your-folder';
$file = "$folder/test.txt";

// work with a transaction
$transactionalFileSystem = new TransactionalFileSystem();
$transactionalFileSystem->createFolder($folder);
$transactionalFileSystem->writeFile($file, 'some string content');
$transactionalFileSystem->commit();

// check that files are actually created
$realFileSystem = new RealFileSystem();
$realFileSystem->getFolderStatus($folder); // will be FileSystemUnitStatus::EXISTS
$realFileSystem->getFileStatus($file); // will be FileSystemUnitStatus::EXISTS

// delete the file
$transactionalFileSystem = new TransactionalFileSystem();
$transactionalFileSystem->deleteFile($file);
$transactionalFileSystem->commit();

// check that files are actually deleted
$realFileSystem = new RealFileSystem();
$realFileSystem->getFolderStatus($folder); // will be FileSystemUnitStatus::EXISTS
$realFileSystem->getFileStatus($file); // will be FileSystemUnitStatus::NOT_FOUND