Many PHP functions have long and descriptive
names. However it may be hard to tell what a
function named glob() does unless you are already familiar with that term from elsewhere. Think of it like a more capable version of the scandir() function. It can let you search for files by using patterns. // get all php files
$files = glob('*.php'); print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php [2] => post_output.php
[3] => test.php
)
*/ You can fetch multiple file types like this: // get all php files AND txt files
$files = glob('*.{php,txt}', GLOB_BRACE); print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php [2] => post_output.php
[3] => test.php
[4] => log.txt
[5] => test.txt
)
*/ Note that the files can actually be returned with a
path, depending on your query: $files = glob('../images/a*.jpg'); print_r($files);
/* output looks like:
Array
(
[0] => ../images/apple.jpg
[1] => ../images/art.jpg )
*/ If you want to get the full path to each file, you can
just call the realpath() function on the returned values: $files = glob('../images/a*.jpg'); // applies the function to each array element
$files = array_map('realpath',$files); print_r($files);
/* output looks like:
Array
(
[0] => C:\wamp\www\images\apple.jpg
[1] => C:\wamp\www\images\art.jpg )
*/