PDA

View Full Version : FN Search cgi script


digital-cipher
08-23-2004, 06:16 PM
Hi all
i am trying to use dswimboy's cgi script to search a virtual directory on my web server.
Problem is it will search using the server path (ie c:\search) but not a virtual path (www.myserver.com\search)
i want the script to search a virtual path then generate a hyperlink to that file.
!!Any Help Please !!! :confused:

The below script is what im using !!!

#!/usr/bin/perl

#Edit this first line to your perl intercepter
#If not this, try #!/usr/local/bin/perl

use File::Find;
use CGI;

$q = new CGI;

$query = $q->param("search");

##############EDITING BEGINS HERE############################

@DIRLIST = ( 'd:');

#Put the partial server path to your directory which keeps your files that you want to be searched. There can be sub-directories within the searched directory.
#Help: You have to get the full server path to the directory where you are keeping your files. It might be something like /usr/pub/www/search
#In this case the 'home' path is /usr/pub/www. You have to replace the home path to ' ../ '
#so the directory in this case would be '../search' NO TRAILING SLASH


print "Content-type: text/html\n\n";

sub search {
if ($_ =~ /$query/i) {
$results++;
$path = $File::Find::name;


print "<body>\n";

#Insert whatever HTML you wish between the above print" and \n";
#DO NOT USE ANY INVERTED COMMONS (') OR QUOTATION MARKS (")

print "<a href='$path' target=_blank>$_</a><br>\n";
}
}

find (\&search, @DIRLIST);

unless ($results) {
print "No Results found\n";
}

dswimboy
10-15-2004, 01:35 PM
i don't know if the script can search virtual paths.

i would recommend searching the local path, and then updating each link. for example, lets say your search returned the following results:
c:\search\index.html
c:\search\home\index.htm
c:\search\larger.html

i would use RegEx to modify the links, making them 'virtual'.

$link =~ s/$c:\\search\\/www.myserver.com\/search/i;

the links would then become:
www.myserver.com/search\index.html
www.myserver.com/search\home\index.htm
www.myserver.com/search\larger.html

you might also want to replace the slashes, so that they all match, but i don't think it's a requirement. most webservers automatically adjust.