search files in directory using php
i have a situation,i am creating a folder everytime when new user register.the folder name is equal to username.so therefore user_data folder contains all开发者_开发知识库 folder which name is equal to username. when user upload something then it directly save to its desired username folder.
so now i want to search perticular file from these folder. i know that, that particular file save in user_data folder but i dont know in user_data foder which folder contain that file. so what will be the code for searching file in directory.
take a look at RecursiveDirectoryIterator
combine it with strstr
or preg_match
glob()
should do the trick. Here's an example of its usage. hope it helps:
$filenames = glob('user_data\\'. $username . '\\*.jpg');
foreach ($filenames as $filename) {
echo $filename ."\n";
}
精彩评论