Using glob() function in PHP
To find pathnames matching a pattern such as .html or .php, you’ll use this glob() function. The return value is an array of files that has the matched pattern that you defined.
Function:
array glob ( string $pattern [, int $flags = 0 ] )
Usage:
foreach (glob("*.htm") as $filename) { echo "$filename size " . filesize($filename) . "\n"; }
You can use this function to manage file system on your server.
Example: Using array_map function to perform a callback to the elements of a given arrays. This script will remove all files that has the pattern “.txt” in a defined directory.
array_map('unlink', glob($my_doc_root . $test_dir."*.txt"));