PHP code example of plumphp / plum-file

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

    

plumphp / plum-file example snippets


use Plum\PlumFile\FileExtensionFilter;

$filter = new FileExtensionFilter('md');
$filter->filter('README.md'); // -> true
$filter->filter('README.html'); // -> false

use Plum\PlumFile\FileExtensionFilter;

$filterArray = new FileExtensionFilter('md', '[filename]');
$filterArray->filter(['filename' => 'README.md']); // -> true
$filterArray->filter(['filename' => 'README.html']); // -> false

$item = new stdClass();
$item->filename = 'README.md';
$filterObject = new FileExtensionFilter('md', 'filename');
$filterObject->filter($item); // -> true
$item->filename = 'README.html';
$filterObject->filter($item); // -> false

$filter = new FileExtensionFilter(['md', 'html']);
$filter->filter('file.md');   // -> true
$filter->filter('file.html'); // -> false
$filter->filter('file.csv`);  // -> false

use Plum\PlumFile\ModificationTimeFilter;

$after = new ModificationTimeFilter(['after' => new DateTime('-3 days')]);
$after->filter('modified-2-days-ago.txt'); // -> true
$after->filter('modified-4-days-ago.txt'); // -> false

$before = new ModificationTimeFilter(['before' => new DateTime('-3 days')]);
$before->filter('modified-4-days-ago.txt'); // -> true
$before->filter('modified-2-days-ago.txt'); // -> false

$range = new ModificationTimeFilter(['after' => new DateTime('-6 days'), 'before' => new DateTime('-3 days')]);
$range->filter('modified-4-days-ago.txt'); // -> true
$range->filter('modified-8-days-ago.txt'); // -> false
$range->filter('modified-2-days-ago.txt'); // -> false

use Plum\PlumFile\FileGetContentsConverter;

$converter = new FileGetContentsConverter();
$converter->convert('foo.txt'); // -> 'content of foo.txt'

use Plum\PlumFile\FileGetContentsConverter;

$converter = new FileGetContentsConverter('file', 'content');
$converter->convert(['file' => foo.txt']);
// -> ['file' => 'foo.txt', 'content' => content of foo.txt']