Glob examples
Shows how to use the glob function to read directory listings as with "opendir" - just easier :-)
$dir = './'; foreach(glob($dir.'*.txt') as $file) { print $file . "\n"; } /* returns: ./dummy.txt ./foo.txt ./ideas.txt ./robots.txt ./scite.txt */ /* ** other examples: */ // also possible: $files = glob('*.*'); sort($files); // This shows how to use the GLOB_BRACE flag: $images = glob("images/{*.jpg,*.gif,*.png}", GLOB_BRACE); print_r($images); /* Valid flags: GLOB_MARK GLOB_NOSORT GLOB_NOCHECK GLOB_NOESCAPE GLOB_BRACE GLOB_ONLYDIR GLOB_ERR see PHP.net manual for more info */
Author:
Jonas John
License:
Public Domain
Language:
PHP
Created:
06/13/2006
Updated:
06/13/2006
Tags:
tutorials, directory functions, files
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
In Array.
I Want Set Path Dynamically From Database But It's Not Working.
My Coad As Follwing I Need Help.
$slIm1=mysql_query("select ImgPath from subcategory_2
where SubCategory='".$id."'");
//Get Path In Array.
while($Path=mysql_fetch_array($slIm1))
{
$files=glob($Path['ImgPath']."*.*"
.'.{jpg,jpeg,png,gif},GLOB_BRACE');
for($i=0;$i<count($files);$i++)
{
$num=$files[$i];
echo "<img src='".$num."'>";
}
Thanks.
When I can find some time beside my job I'll post some more snippets in 2010.
Thank you Jonas