I try to fix my search code so that not just files with ".png" extensions will be found, but also all files with ".map, .jpg, .gif".
When i delete the '.png'; people have to type in the full filename like "test.png"...
Code:
<?php
$dirname = 'assets/db/';
$findme = $_GET['search']. '.png'; // this is where I add the ".png" manually...
$dirs = glob($dirname.'*', GLOB_ONLYDIR);
$files = array();
function findAllDirs($start) {
$dirStack=[$start];
while($dir=array_shift($dirStack)) {
$ar=glob($dir.'/*',GLOB_ONLYDIR|GLOB_NOSORT);
if(!$ar) continue;
$dirStack=array_merge($dirStack,$ar);
foreach($ar as $DIR)
yield $DIR;
}
}
$result= [];
foreach(findAllDirs($dirname) as $d) {
$f = glob( $d .'/'. $findme );
if( count( $f ) ) {
$files = array_merge( $files, $f );
}
}
if( count($files) ) {
foreach( $files as $f ) {
echo "<h3> <a href='{$f}'> $findme </a>";
echo "<img src='$f'/>";
echo "</h3> <hr> <br>";
}
} else {
echo "<h3> Nothing was found. Sorry. </h3>";
echo '<img src=""/>';
}
?>
I hope you can help me. Thanks