php - 向搜索表单添加错误

标签 php

我尝试在搜索表单中添加一个错误,但它不起作用,如果你想看演示,你可以继续 Svapomc.com ,请有人可以帮助我吗?非常感谢

    </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>";
}
?>

这是我认为问题出在其他代码但我不知道的所有代码

最佳答案

也许你有文件,但没有匹配......

$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"/>';
}

关于php - 向搜索表单添加错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43843510/

相关文章:

java - 从 android 到 PHP 的 HTTP post 调用?

PHPStan 忽略错误正则表达式

javascript - Jquery 倒计时在 Safari 中显示 NaN,在 Chrome/Firefox 中工作正常

PHP 将特殊字符转换为 HTML 实体

php - WordPress fatal error : Uncaught Error after failed auto update to 5. 1.1

php - 如何更新值多对多 Laravel

php - Laravel Eloquent 地结合 max() 和 where() 或having()

PHP连接但无法查询MYSQL数据库

带有/distinct 和其他参数的 PHP/MySQLi 查询

PHP 禁用 ipv6