Add an error to the search form
I tried to add an error to the search form, but it doesn't work, if you want to see a demo you can go to Svapomc.com , can anyone please help me? Many thanks
</html>
<head>
<link href="cerca.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form action="" method="get">
<input type="text" name="search" placeholder="Cerca la mappa da scaricare (puรฒ essere pure incompleto)"/>
<input type="submit" value="Cerca"/>
</form>
<body>
</html>
<?php
//--- get all the directories
$search = $_GET["search"];
$dirname = 'maps';
$findme = "*.bz2";
$dirs = glob($dirname.'*', GLOB_ONLYDIR);
$files = array();
//--- search through each folder for the file
//--- append results to $files
foreach( $dirs as $d ) {
$f = glob( $d .'/'. $findme );
if( count( $f ) ) {
$files = array_merge( $files, $f );
}
}
if( count($files) ) {
foreach( $files as $f ) {
if(strpos($f, $search) !== false and strpos($f, '.nav') === false and strpos($f, '.jpg') === false and strpos($f, '.txt') === false and strpos($f, '.jpe') === false or !isset($_GET["search"]) or $search == ""){
$f1 = str_replace('maps/', '', $f);
$f1 = str_replace('.bz2', '', $f1);
$f1 = str_replace('.bsp', '', $f1);
echo "<div class='ciao'><p>{$f1} <a download href='{$f}'>Download</a></p></div><br>";
}
}
} else {
echo "<p>Error message here</p>";
}
?>
This is all code, I think the problem is different, but I don't know
+3
source to share
1 answer
You may have files, but no matches ...
$file_found = false;
if( count($files) ) {
foreach( $files as $f ) {
if(strpos($f, $search) !== false and strpos($f, '.nav') === false and strpos($f, '.jpg') === false and strpos($f, '.txt') === false and strpos($f, '.jpe') === false or !isset($_GET["search"]) or $search == ""){
$f1 = str_replace('maps/', '', $f);
$f1 = str_replace('.bz2', '', $f1);
$f1 = str_replace('.bsp', '', $f1);
echo "<div class='ciao'><p>{$f1} <a download href='{$f}'>Download</a></p></div><br>";
$file_found = true;
}
}
}
if(!$file_found){
echo "<p>Non รจ stata trovata nessuna mappa con questo nome</p>";
echo '<img src="yourimagehere.jpg"/>';
}
+2
source to share