- How to search files in a directory with php.
- search a file from a folder with php.
This script searches the files located in folder by matching keyword.
Script
$string_to_search='btn';
$path='pictures/products/';
$handle=opendir($path);
while(($file = readdir($handle))!==false){
if ($file!="." && $file!=".."){
if(strstr($file,$string_to_search)!==false){
echo $file . ', ';
}
}
}
Output
btnDelete.gif, Previewbtn.gif

Leave A comment
Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *