How to make php files searcher ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ???

17th Oct 2018, 1:28 PM
Googel
Googel - avatar
4 Answers
+ 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 . "]&nbsp;&nbsp;"; if ($i < 10) { echo "&nbsp;&nbsp;&nbsp;"; } elseif ($i < 100) { echo "&nbsp;&nbsp;"; } else { echo "&nbsp;"; } echo $res[$i] . "<br />"; } echo "<br />"; for ($i = 2; $i < count($res); $i++) { dirsearch($file . "/" . $res[$i]); } } } dirseach('YourDirName'); ?>
21st Oct 2018, 9:50 AM
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱 - avatar
+ 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...
21st Oct 2018, 8:30 AM
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱 - avatar
+ 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...
18th Oct 2018, 2:50 PM
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱
Ronen Gil רונן גיל رونين جيل 🏳️‍🌈♾🇹🇩🇮🇱 - avatar
+ 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.
21st Oct 2018, 5:53 AM
Googel
Googel - avatar