PHP code example of jc21 / filelist

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

    

jc21 / filelist example snippets




use jc21\FileList;

$fileList = new FileList;

$items = $fileList->get('/path/to/files');

// Use the items array
print '<pre>';
foreach ($items as $item) {
    if ($item[FileList::KEY_TYPE] == FileList::TYPE_DIR) {
        print 'd' . "\t" . $item[FileList::KEY_NAME] . PHP_EOL;
    } else {
        print 'f' . "\t" . $item[FileList::KEY_NAME] . "\t" . $item[FileList::KEY_SIZE] . "\t" . date('Y-m-d', $item[FileList::KEY_DATE]) . PHP_EOL;
    }
}
print '</pre>';

$items = $fileList->get('/path/to/files', FileList::TYPE_DIR);

$items = $fileList->get('/path/to/files', FileList::TYPE_FILE);

$extensions = array('jpg', 'png', 'jpeg', 'gif');
$items      = $fileList->get('/path/to/files', FileList::TYPE_DIR, FileList::KEY_NAME, FileList::ASC, null, $extensions);

$items = $fileList->get('/path/to/files', FileList::TYPE_DIR, FileList::KEY_SIZE, FileList::DESC);
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php