+ 5
How to make php files searcher ?
How can we make a search webpage made by php which can : 1.) Search files of current directory 2.) Search files of sub directory of current directory ???
4 Antworten
+ 5
Like so:...
<?php
/*********************************************************
* For security reasons, this script doesn't work here. *
* AT YOUR OWN RISK!!!, You can copy it to your server *
* WITHOUT ANY KIND OF WARRANTY! *
* written by Ronen Gil *
*********************************************************/
function dirsearch($file)
{
if (is_dir($file))
{
echo "in " . $file . ":<br />";
$res = scandir($file);
for ($i = 0; $i < count($res); $i++)
{
echo "[" . $i . "] ";
if ($i < 10)
{
echo " ";
}
elseif ($i < 100)
{
echo " ";
}
else
{
echo " ";
}
echo $res[$i] . "<br />";
}
echo "<br />";
for ($i = 2; $i < count($res); $i++)
{
dirsearch($file . "/" . $res[$i]);
}
}
}
dirseach('YourDirName');
?>
+ 5
SP coder Your search engine can not be the scandir() function itself, but it should be a recursive function that calls scandir() and examines each result with is_dir() http://php.net/manual/en/function.is-dir.php and if the filename is a directory - to call your function again... That is to say that scandir() is not recursive. It doesn't check sub-dirs... But your search engine can do it...
+ 4
You can start by reviewing the output of scandir() - you should search within this output...
http://php.net/manual/en/function.scandir.php
Be aware, that this is the server's directory and not the Client's - since PHP is a server based language...
+ 4
I agree you Ronen Gil
I know that.
But "scandir('directory-Path')" is not enough for scanning sub-directories too.
Did you got what I meant to say?
I hope I will get my best answer.