wherw/scan-path

Recursive directory scanner to search for files using the file extension or mime type

v1.0.4 2020-12-07 00:55 UTC

This package is auto-updated.

Last update: 2024-04-10 18:14:45 UTC


README

The library is used to get a list of files in a given category. When you find subdirectories, a list of files is also extracted from it.

REQUIREMENTS

The minimum requirement by this project template that your Web server supports PHP 7.1.0.

INSTALLATION

Install via Composer

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

composer require wherw/scan-path

CONFIGURATION

Create an instance of the ScanPath class

Create an instance of the ScanPath class. To search for files using this library, you need to call the setExtension method with a parameter in which you need to specify the array of file extensions you want to find. If you want to find files using mimeType, you need to call the setMimeType method, in which you need to specify the type of file you want to find. Supported types:

  • application;
  • audio;
  • image;
  • multipart;
  • text;
  • video;

But keep in mind that this method takes much longer than the setExtension method

EXAMPLE

$scan = new \wherw\ScanPath();
$scan->setPath('/mnt/music/');
$scan->setExtension([
    'm4a',
    'flac',
    'ogg',
    'mp3',
    'wma',
    'wav',
    'ape',
    'aac'
]);

$files = $scan->getFiles();
$scan = new \wherw\ScanPath();
$scan->setPath('/mnt/music/');
$scan->setMimeType('audio');

$files = $scan->getFiles();
$scan = new \wherw\ScanPath();
$fileTypes = $scan->setPath('/mnt/')->getFileTypes();