isaac_cm Posted August 30, 2007 Share Posted August 30, 2007 Hello, I found many free scripts on the net to make file search , but I dont know which is better can you suggest one , I have no time to make one myself Note: I need it to search specific folder but also go to sub folder and to find based on limited number of extensions thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/67342-file-search-ready-to-use-script/ Share on other sites More sharing options...
GingerRobot Posted August 30, 2007 Share Posted August 30, 2007 If you want someone to do this for you, i suggest you try the freelance forum. This forum is to help you with the things that you are attempting to do. If you do want some help, then take a look at the following bit of code: <?php function no_of_files($start_dir,$sub_dir=FALSE){ $no_of_files=0; if($sub_dir === false){ $handler = opendir($start_dir); }else{ $start_dir = $start_dir.$sub_dir; $handler = opendir($start_dir); } while(false !== ($file = readdir($handler))){ if($file != '.' && $file != '..'){ if(is_dir($start_dir.'\\'.$file)){//if this is a directory, recall the function with the subdirectory defined $dir_name = '\\'.$file; echo $dir_name.'<br />'; $no_of_files += no_of_files($start_dir,$dir_name); }else{//is a file, so increase our counter //here is where you would check to see if the file is the one you are looking for $no_of_files++; } } } return $no_of_files; } echo no_of_files('C:\Documents and Settings\Ben\My Documents\My Music'); ?> That was a function i wrote to count the number of files in a given folder and all its subfolders. It wouldn't be too hard to modify the function to accept a 3rd parameter - the file you are searching for. It would then be a case of adding in a test to see if the file currently being looked at in the loop is the one you are after. Quote Link to comment https://forums.phpfreaks.com/topic/67342-file-search-ready-to-use-script/#findComment-337882 Share on other sites More sharing options...
isaac_cm Posted August 30, 2007 Author Share Posted August 30, 2007 thanks I was looking for something ready like CMS, to use your function I have to return all the files matches the search parameters in an array , right ? Quote Link to comment https://forums.phpfreaks.com/topic/67342-file-search-ready-to-use-script/#findComment-337886 Share on other sites More sharing options...
GingerRobot Posted August 30, 2007 Share Posted August 30, 2007 As i said, the function i posted doesn't already do what you're trying to do. I was basically pointing you in the right direction as far as a recursive function is concerned(your function needs to call itself to allow you to search through an undefined level of subdirectories) You'll need to modify it. How you modify it rather depends on how you want it to work. You could simply set it up to echo something when it finds the file. That would be the easiest modification, though perhaps least useful. I would personally alter what the function returns; i woud have it return true on a match, and false with no match (if you take this method, you'll need to add an if statement to test the result of the function where it is called by itself) Quote Link to comment https://forums.phpfreaks.com/topic/67342-file-search-ready-to-use-script/#findComment-337894 Share on other sites More sharing options...
isaac_cm Posted August 30, 2007 Author Share Posted August 30, 2007 Dear Sir, I am looking for something like that one: http://filenice.com but with the following features (image browser): - display and search only for images - browse specific folder - return selected image name thanks Quote Link to comment https://forums.phpfreaks.com/topic/67342-file-search-ready-to-use-script/#findComment-338053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.