The documentation page on glob() has this example:
<?php foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; } ?>
But to be honest, I don’t understand how this can work.
The array produced by glob("*.txt") will be traversed, but where does this array come from? Is glob() reading a directory? I don’t see that anywhere in the code. Glob() looks for all matches to *.txt
But where do you set where the glob() function should look for these strings?
Without any directory specified glob() would act on the current working directory (often the same directory as the script, but not always).
To make it more useful, use a full path such as glob(‘/var/log/*.log’). Admittedly the PHP documentation doesn’t make the behaviour clear, but glob() is a C library function, which is where it originates from.