Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 54

Thread: search a directory on my site

  1. #21
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok I know you are probably getting tired of me so hopefully this post will solve it all.

    I put the quotes in and now I am getting this

    Warning: strpos(): Empty delimiter. in /home/content/d/e/r/derekm806/html/ordinances.php on line 69
    And Line 69 is this:

    if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    And just for further refreshing here is the whole code again:

    <?php
    function searchfiles($search,$dir) {
    $results = array();
    $n=0;
    $opendir = opendir($dir);
    while ($file = readdir($opendir)) {
    if (in_array($file,array('.','..','otherfile.ext','....'))) continue;
    //leave '.' and '..', and add any other files to skip... but try to keep mostly only searched files in this directory
    if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    $array[$n] = $file;
    $n++;
    }
    return $array;
    }


    if (isset($_POST['search']) )

    print_r(searchfiles($_POST['term'], 'ord')); //set mydocs to your directory
    //$search must be the text to match


    else {
    ?>
    <form action="" method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>
    And you said earlier that something about assuming $dir and $file are set correctly, where was i susposed to set that at

    Thanks
    DM

  2. #22
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by derekm View Post
    And you said earlier that something about assuming $dir and $file are set correctly, where was i susposed to set that at
    It would be on this line:

    Code:
    print_r(searchfiles($_POST['term'], 'ord')); //set mydocs to your directory
    The part in red is the directory, the file is found in that directory and "automatically" defined; if that makes sense.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #23
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    so your saying I have it right?

  4. #24
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    If the directory you are searching in is called "ord", then yes. If not, then you need to change it to the directory you wish to search through.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #25
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well that is the exact directory and it is not working for some reason...

    what does "Empty delimiter" mean?

  6. #26
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    With this php code

    <?php
    function searchfiles($search,$dir) {
    $results = array();
    $n=0;
    $opendir = opendir($dir);
    while ($file = readdir($opendir)) {
    if (in_array($file,array('.','..','otherfile.ext','....'))) continue;
    //leave '.' and '..', and add any other files to skip... but try to keep mostly only searched files in this directory
    if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    $array[$n] = $file;
    $n++;
    }
    return $array;
    }


    if (isset($_POST['search']) )

    print_r(searchfiles($_POST['term'], 'ord')); //set mydocs to your directory
    //$search must be the text to match


    else {
    ?>
    <form action="" method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>
    I am getting no form at all and getting this on my page..

    Warning: strpos(): Empty delimiter. in /home/content/d/e/r/derekm806/html/ordinances.php on line 69

    Warning: strpos(): Empty delimiter. in /home/content/d/e/r/derekm806/html/ordinances.php on line 69

    Warning: strpos(): Empty delimiter. in /home/content/d/e/r/derekm806/html/ordinances.php on line 69
    LINE 69
    if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    Any ideas.....

  7. #27
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not sure if action="" is invalid. If so, just use the name of your page. It's possible to generate this with PHP, but it was giving you errors before, so I don't see the point.

    As for the strpos() error, I'm assuming that either $search or file_get_contents() is blank. You can suppress the error using:
    if (!@strpos($search,file_get_contents($dir.'/'.$file))) continue;

    But I'm not sure if that will help, if something is going wrong.

    You're not getting any results at all?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #28
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok Here is the web site address. Maybe if you see what it is doing you will be able to tell more about it

    www.bayarkansas.org/ordinances.php

    Thanks
    DM

  9. #29
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Nothing returns results. I assume you have 3 files being searched right now?


    The code above should work, if the system is setup correctly (sending the form, etc). However, try changing this:
    if (isset($_POST['search']) )
    to:
    if (isset($_POST['term']))

    See if that helps.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #30
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nothing returns results. I assume you have 3 files being searched right now?


    The code above should work, if the system is setup correctly (sending the form, etc). However, try changing this:
    if (isset($_POST['search']) )
    to:
    if (isset($_POST['term']))

    See if that helps.
    Actually there is a couple hundred files in that directory. But there may only be a few with the term I am searching

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
  •