jc21 / filelist
File Listing helper class
Installs: 1 131
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- victorjonsson/markdowndocs: dev-master
This package is auto-updated.
Last update: 2024-05-28 10:58:44 UTC
README
- List files from a directory
- Filter for only directories, files or file types
- Sort and limit the listing items
Installing via Composer
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version:
composer.phar require jc21/filelist
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Using
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>';
Or to get only directories:
$items = $fileList->get('/path/to/files', FileList::TYPE_DIR);
Or only files:
$items = $fileList->get('/path/to/files', FileList::TYPE_FILE);
Or only files of a certain extension:
$extensions = array('jpg', 'png', 'jpeg', 'gif'); $items = $fileList->get('/path/to/files', FileList::TYPE_DIR, FileList::KEY_NAME, FileList::ASC, null, $extensions);
Order by the Size descending:
$items = $fileList->get('/path/to/files', FileList::TYPE_DIR, FileList::KEY_SIZE, FileList::DESC);