Results 1 to 4 of 4

Thread: A "search" script

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default A "search" script

    I really don't know how to explain this but here it goes.

    Ok I need a script that when it's clicked will find a file and open it in my directory I select and if it isn't to display a error message saying sorry or something along those lines.

    I don't really know if I'm explaining it right but something like (search for this!) and the link would be like search.php?=(title here) something like that, Blah I'm terrible at explaining this >.< Any help would be awesome. If you need more of a idiotic explaination just ask >.<

    Willing to pay for one.

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    If you are talking about a php file, This would be rather easy:
    The search page:
    Code:
    <form action="search.php" method=get>
    <input type="text" name="filename">
    <input type="submit" value="Open">
    </form>
    the php page:
    Code:
    <?
    $filename = $_GET['filename'];
    if(!file_exists($filename))
    {
    header("location: errorpage.htm");
    }
    else
    {
    header("location: $filename");
    }
    ?>
    untested.
    This is only if the person knows the exact filename, not really a "search". Any more Questions, don't resist.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. The Following 2 Users Say Thank You to fileserverdirect For This Useful Post:

    Bluz (03-08-2008),scottjcampbell (03-12-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    That's pretty well exactly what I want Only a couple things, Is there a way to just make it a text link instead of a search field? And second is there a way to make it only search one directory?

    example, the search is on a page thats /cats/cat1.php but you want it to look for the file under /dogs/

    Thanks!

  5. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Yes,
    just provide a link like this:
    Code:
    <a href="search.php?filename=afile.html">Go to afile.html</a> (If it exists)
    and a php file like this:
    Code:
    <?
    $filename = $_GET['filename'];
    if(!file_exists("../dogs/$filename"))
    {
    header("location: errorpage.htm");
    }
    else
    {
    header("location: ../dogs/$filename");
    }
    ?>
    -----------------------------------------------------
    And if you want a personal error page on search.php:
    Code:
    <?
    $filename = $_GET['filename'];
    if(!file_exists("../dogs/" . $filename))
    {
    echo "Sorry! The file \"<i>$filename</i>\" does not exist.";
    // use the echo command to output more html.
    }
    else
    {
    header("location: ../dogs/$filename");
    }
    ?>
    --------------------------------------
    or if you keep the first example... (in bold)
    Code:
    if(!file_exists("../dogs/" . $filename))
    {
    header("location: errorpage.php?filename=$filename");
    }
    errorpage.php?filename=afile.html
    Code:
    <?php
    $filename = $_GET['filename'];
    ?>
    <html>
    <!-- your custom html page here-->
    Sorry! The file "<i><?php echo $filename; ?></i>" does not exist.
    <!-- your custom html page here-->
    </html>
    untested.
    May sound a little confusing, but any more questions, please post
    Last edited by fileserverdirect; 03-08-2008 at 04:33 PM. Reason: code error
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

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
  •