Get a glob listing by expanding a comma separated list in curly braces
The following glob takes an array of extensions, implodes them by a comma, and then inserts that string into curly braces. The glob function itself needs the GLOB_BRACE setting.
This glob will return all entries in a directory of the form: *.txt, *.zip, *.gif, *.jpg and *.png.
<?php
$config = array("txt", "zip", "gif", "jpg", "png");
$a_files = glob("*.{" . implode(",",$config['allowed_extensions']) . "}",GLOB_BRACE);
print_r($a_files);
?>
$config = array("txt", "zip", "gif", "jpg", "png");
$a_files = glob("*.{" . implode(",",$config['allowed_extensions']) . "}",GLOB_BRACE);
print_r($a_files);
?>
[Click to add or edit comments])
Please prepend comments below including a date