Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 54

Thread: search a directory on my site

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

    Default

    Quote Originally Posted by djr33 View Post
    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.
    I did what you said above and still got

    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
    Any Suggestions or am I totally screwed
    DM

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

    Default

    Could any of the files have no content?

    If so, that could be the reason you are getting the empty message.

    Make this line: if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    This:
    $fc = file_get_contents($dir.'/'.$file)
    if ($fc == '') continue;
    if (!strpos($search,$fc)) continue;
    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

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

    Default

    Quote Originally Posted by djr33 View Post
    Could any of the files have no content?

    If so, that could be the reason you are getting the empty message.

    Make this line: if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    This:
    $fc = file_get_contents($dir.'/'.$file)
    if ($fc == '') continue;
    if (!strpos($search,$fc)) continue;
    Ok I did what you said but now the page will not load and all that i see is a this
    Parse error: parse error, unexpected T_IF in /home/content/d/e/r/derekm806/html/ordinances.php on line 69

  4. #34
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Just so I know we are on the same page the only thing I needed to change in the code below is the dir in print_r(searchfiles($_POST['term'], 'ord')); //set mydocs to your directory
    <?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['term'])) {

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

    else {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>

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

    Default

    You should use the new lines of code that I added, to error correct if a file IS empty. However, there was a typo. I forgot a semicolon at the end of a line.
    $fc = file_get_contents($dir.'/'.$file);
    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

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

    Default

    $fc = file_get_contents($dir.'/'.$file)
    if ($fc == '') continue;
    if (!strpos($search,$fc)) continue;
    Does the above code need to be exactly like it looks or on one line

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

    Default

    That's right. But again, it's missing a semi colon. Add that to the first line, like in my last post.
    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. #38
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Could any of the files have no content?

    If so, that could be the reason you are getting the empty message.

    Make this line: if (!strpos($search,file_get_contents($dir.'/'.$file))) continue;
    This:
    $fc = file_get_contents($dir.'/'.$file)
    if ($fc == '') continue;
    if (!strpos($search,$fc)) continue;
    after doing the above i am not getting no warning now;

    Now I am getting a refreshed page with no form to fill out?
    What next
    ????????
    I know I am probably getting on your nerves sorry
    DM

  9. #39
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    djr33, you're missing one key point.
    Quote Originally Posted by Original Question
    300 word/pdf files
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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

    Default

    What do you mean tech_support

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
  •