Search files in folders and sub folders in php using glob

Guys,

I found the solution for searching a filename in directories and sub directories using glob() in php..

Pls find the below code:

function recursiveGlob($dir, $ext) {

$strsear=$_POST[“stringsearch”];

$globFiles = glob(“$dir”.DIRECTORY_SEPARATOR.”$strsear*.$ext”);
$globDirs = glob(“$dir/*”, GLOB_ONLYDIR);

foreach ($globDirs as $dir) {
recursiveGlob($dir, $ext);

}

foreach ($globFiles as $file=>$v) {

print “$v”; 
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s