View Full Version : 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.
fileserverdirect
03-08-2008, 01:44 AM
If you are talking about a php file, This would be rather easy:
The search page:
<form action="search.php" method=get>
<input type="text" name="filename">
<input type="submit" value="Open">
</form>
the php page:
<?
$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.
That's pretty well exactly what I want :D 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!
fileserverdirect
03-08-2008, 04:29 PM
Yes,
just provide a link like this:
<a href="search.php?filename=afile.html">Go to afile.html</a> (If it exists)
and a php file like this:
<?
$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:
<?
$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)
if(!file_exists("../dogs/" . $filename))
{
header("location: errorpage.php?filename=$filename");
}
errorpage.php?filename=afile.html
<?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 :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.