folderblog
What is folderblog?
Folderblog is a free PHP script that automatically displays the images placed in a given directory, no database needed. It can be used as a blog or gallery — and anything in between.

» demo blog   » learn more   » download now

Discussion
glob() not a safe function(back to index)
Howdy. glob() is a potentially dangerous function with respects to file enumeration and the like so I suggest that it be replaced with something like the following:

function pseudo_glob($dir,$str='',$only_dir=0)
{
$list=array();

if(strlen($str)>1)
{
// first grab current
if(is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if(fnmatch($str,$file))
{
if($only_dir)
{
if(is_dir($dir.'/'.$file))
{
array_push($list,$dir.'/'.$file);
}
}
else
{
array_push($list,$dir.'/'.$file);
}
}
}
closedir($dh);
}
}
}
return $list;
}

The calls in the code to glob would then be changed to pass the start directory separate from the search string. Some hosts will not allow the use of glob() so the above code lets you work around that.

Cheers
posted by moron on 31 Mar 06 at 5:13 PM
Post a Reply:

Name:    Remember me
URL:    
(include http:// or mailto:)
(back to index)