Search files in folders and subfolders in php


I am back..with couple of hours working on file search in directories and sub directories..i figured on my own. Its pretty easy to search a file in directories and sub directories at a time.

A small template design to show search text box is already posted in my previous post

Lets go directly to the main is the snippet..

Code Snippet:

$path = realpath(‘C:\wamp\www\apps’);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
foreach( $resultspath as $value)
echo $value.”<br/>”;


Output will display filename that are existed in directory and sub-directory.

Folder structure:




Say i was trying to find a “zend.jpg” file from the above folder structure..just type zend and hit you can view 2 paths as listed above. Hope it helps you.. 😀

Stay tuned to sathyalog 🙂


Leave a Reply

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

You are commenting using your 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