PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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-将错误添加到搜索表单全部内容,希望文章能够帮你解决php-将错误添加到搜索表单所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: