Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 54

Thread: search a directory on my site

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

    Default

    Ok Last post for this: sorry to be a such a moron but now I am getting this

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

    This is what is on Line 69 of the php file.

    if (!strpos($search,file_get_contents($ord.'/'.$ord))) continue;


    Could you tell me what I am doing wrong.

    DM

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

    Default

    Is the variable "$ord" defined elsewhere in the script? If not, that would be the reason why. I recommend using djr's script; and if needed, using my modification to it.

    Hope this helps.
    "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. #13
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, to start, you're using the same variable twice.

    So, that's like searching for directory/directory, or file.ext/file.ext, neither of which will end up giving you any results.

    file_get_contents() returns the data in a file on your server. It uses a path to find the file. dir1/dir2/dir3/file.ext is an example of this.

    Using $dir.'/'.$file SHOULD return directoryname/filename.extension, assuming $dir and $file are set correctly.

    In the script I wrote, both of these are set. I'm not sure why you are changing the variable names. You're welcome to do so, but...
    1. Changing the names can cause problems (and likely has) since you need to be completely consistent throughout the script so no references are lost.
    2. Using generic names like I did (though unrelated to whether the script works or not, since variable names serve no purpose but identification) is helpful because you know what it is, within the function. Using "$dir" makes more sense than "$images", just as naming a variable "$number" makes more sense than "$one", etc. It's up to you, but I like having generic names within a function. In the rest of your script, do whatever you want (as long as it makes sense, since that's the most important part-- being able to follow what's going on).

    At this point, I'd say decide why you are changing the variable names. You could try going back or you could be sure that all instances have changed.
    You may want to paste the full source code here (skip all HTML as that won't be helpful).

    EDIT: Sorry, testingsite. I was writing while you posted.
    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

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

    Default

    Thanks Both of you Give me a minute and I will redo it to what you originally had and post what I have so for here so you can see what I have

    Thanks a bunch
    DM

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

    Default

    Ok here is what I have:

    <?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="<?php echo $_SERVER['PHP_SELF'];?> method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>
    When I post it I go to the form type in a key word to search and I am getting a page not found and the url is:

    This is what I have can you tell what is wrong

    I am kind of getting this a little better so maybe with you guys help I wont have to bother ya much more.

    Thanks
    DM

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

    Default

    Sorry about that, forgot to add a closing quote after the form action like so:

    Code:
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    That should fix it
    "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

  7. #17
    Join Date
    Jul 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok That made it stop giving me the page not found and any errors so we are getting somewhere but no all that it is doing is when i type a word in it just refreshes the page basically and doesnt show any results.

    here is what I have

    <?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="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>

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

    Default

    Not sure if this will work or not, but you could try this:

    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;
    $results[$n] = $file;
    $n++;
    }
    return $results;
    }
    
    
    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="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    Search Term: <input type="text" name="term"> <input type="submit" name="search">
    </form>
    <?php
    }
    ?>
    Changes made are in red. Hope this helps.
    "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

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

    Default

    <form action="<?php echo $_SERVER['PHP_SELF'];?> method="POST">
    There's no close quote on the action.

    I have no idea why it's generating such a string in the URL, but there's no real point in setting the action to that anyway. Using simply action="" will go to the same page.
    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. #20
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Using simply action="" will go to the same page.
    I was under the impression that that was invalid, but could be wrong. Anyways, I fixed that in my few posts as well as pointed it out about the closing quote. As for the script refreshing to itself, not sure what would be causing that.
    "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

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
  •