Php 在搜索表单中添加错误
我试图在搜索表单中添加一个错误,但它不起作用,如果你想看演示,你可以继续,请有人能帮我吗?非常感谢Php 在搜索表单中添加错误,php,Php,我试图在搜索表单中添加一个错误,但它不起作用,如果你想看演示,你可以继续,请有人能帮我吗?非常感谢 </html> <head> <link href="cerca.css" rel="stylesheet" type="text/css"/> </head> <body> <form action="" method="get"> <input type="text" name="
</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"/>';
}
$file\u found=false;
如果(计算($文件)){
foreach($f文件){
if(strpos($f,$search)!==false和strpos($f,'.nav')==false和strpos($f,'.jpg')==false和strpos($f,'.txt')==false和strpos($f,'.jpe')==false或!isset($\u GET[“search”])或$search==“”){
$f1=str_replace('maps/','','$f);
$f1=str_替换('.bz2','$f1);
$f1=str_替换('.bsp','$f1);
回声“{$f1}
”;
$file\u found=true;
}
}
}
如果(!$file\u找到){
echo“Nonèstata trovata nessuna mappa con questo nome”;
回声';
}
什么不起作用?你得到一个php错误?你应该看到的时候却看不到图像?你得到了下载链接,但期望收到错误消息?检查你的计数。如果(count($files)>0{不,我想在我按send时看到错误消息,如果文件不存在,网站会告诉你:文件不存在或类似的东西我没有类似if(count($files)>0的东西,我需要在那里添加这个。不,抱歉,伙计,它工作了,我无法复制代码,非常感谢