SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Non-Member
    Join Date
    Jun 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to search files on server

    I'm using MySQL and php. How can I search for specific words on a server folder? This will not be a user's search, but purely backend, mainly to find a specific file that has been created, easily.

    Is there a script I can load on the server? Otherway?

    Thank you.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lets suppose your searching filename is myfile.txt and you go like this:
    PHP Code:
    $dir "/etc/php5/";
    $search "myfile.txt";

    if (
    is_dir($dir)) {
        if (
    $dh opendir($dir)) {
            while ((
    $file readdir($dh)) !== false) {
                if(
    $file == $search)
                   echo 
    "File found.";
                   break;
            }
            
    closedir($dh);
        }

    Umm I am not sure how much your problem i understand.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    Non-Member
    Join Date
    Jun 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you for your input. before I try start using it, I want to try to clarify myself.

    I have many php files on my server in one main folder. I want to be able to search those files. Let's say the words "Thank you. Your form has been submitted." is in one of those files. Instead of trying to figure out which file was created that will display this message for the user, I want to be able to search that entire folder, for those words. Ex., "form has been submitted"...when I type those words into the search feature, I want to be able to see which files containt those words (anywhere in those files). Doing so will thus either bring up a list of all the files with those words, or somehow else showing me which files contain those words.

    The searched files are also in various subfolders.

    I hope I made myself more clear.

    Thank you

  4. #4
    SitePoint Zealot Ripe's Avatar
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use rajug's example and modify it to the use readfile() function and possiblely preg_match() function. I guessing that would work.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont think that it is easier to search all files and their contents of a directory, but you can give a try with some functions like of PHP i.e. glob(), file_get_contents(),fread(), etc. since i dont have any full code of such.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •