PHP code example of noroman / filestorage

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

    

noroman / filestorage example snippets



FileStorage\Exceptions\DataException;
use FileStorage\Exceptions\FileStorageException;
use FileStorage\Exceptions\NotFoundException;
use FileStorage\FileStorage;

try {
    $fs = new FileStorage(__DIR__ . '/storage');
} catch (FileStorageException $e) {
    die($e->getMessage());
}

$data = [
    'title' => 'Title',
    'desc' => 'Description',
    'h1' => 'H1',
];

try {
    $fs->save('page', $data);
} catch (DataException $e) {
    die($e->getMessage());
}

try {
    $d = $fs->load('page', $data);
} catch (DataException $e) {
    die($e->getMessage());
} catch (NotFoundException $e) {
    die($e->getMessage());
}

print_r($d);