Greetings!
I am building a simple form based app to search for files on a server.
I want the user to enter a suffix for the file to look for and click the name of the matching to open it in a new window.
This is the source code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="search.php" method="post">
file suffix to search: <input type="text" name="filesearch" />
<input type="submit" />
</form>
</body>
</html>
This is the code for the search:
<?php
$mysearch = $_POST['filesearch'];
$mydir = "/vendors/logfiles/PASS";
$dir = opendir($mydir);
if ($dir ) {
//List files in directory
while (($file = readdir($dir)) !== false)
//Ignores OS stuff.
if ($file != "." && $file != "..") {
if (preg_match('/.'.$mysearch. '$/', $file)) {
//Creates hyperlink to open file in new windows upon selection.
echo '<a href="' . $mydir . '/' . $file
. '" target="_blank">' . $file . "</a><br>";
}
}
closedir($dir);
} else { echo "opendir() returned FALSE!<br>";
exit;}
?>
The script works but the problem is that the hyperlink I create is wrong ; Obviously I get a "404 not found" error when I click it.
Instead of my URL being
/vendors/logfiles/PASS/B0232134_2009_05_01.PASS
I get
http://localhost/vendors/logfiles/PASS/B0232134_2009_05_01.PASS
How can I correct this? Can someone please help?
Thanks.
Al.