Hi guys
I have a problem with the following script.
The search form is searcher.html and is:
==========================
==========
==========
==========
====== searcher.html
<form action="/cgi-bin/searching
.cgi" method="post">
<input type="text" name="query" size="50" />
<input type="submit" />
</form>
==========================
==========
==========
==========
====== searching.cgi
#!c:/perl/bin/perl.exe
use strict;
use CGI qw(:standard);
use File::Find;
my $query = param("query");
print header();
print start_html();
print "\n<p>For the query $query, these results were found:</p>\n<ol>\n";
undef $/;
find ( sub {
return if ($_ =~ /^\./);
return unless ($_ =~ /\.txt/i);
stat $File::Find::name;
return if -d;
return unless -r;
open(FILE, "< $File::Find::name") or return;
my $string = <FILE>;
close (FILE);
return unless ($string =~ /\Q$query\E/i);
my $page_title = $_;
if ($string =~ /<title>(.*?)<\/title>/is)
{
$page_title = $1;
}
print "<li><a href=\"$File::Find::name\"
>$page_tit
le</a></li
>\n"; #Here we output our link.
},
'/wamp/'
);
print "</ol>\n";
print end_html();
==========================
==========
==========
==========
========
What happens is that the script returns the files with the search criteria in correctly. For example,
If i enter on the form 'test' for the text to find.
The problem is when I click on one of thos results, it goes to the wrong url.
If one of the results is listed as:
test.txt
And I click on this result in the browser, it takes me to:
http://localhost/wamp/www/hi/test.txtwhich give me 'Web page unavailable".
The correct path should be:
http://localhost/hi/test.txtin which case, it is displayed correctly.
--------------------------
----------
----------
--------
My document root is c:\wamp\www
Search.html is in c:\wamp\www
Searching.cgi is in c:\wamp\apache2\cgi-bin
Any help appreciated.
Start Free Trial