php搜索已发布的文件

php搜索已发布的文件,php,file-io,search-engine,displayobject,Php,File Io,Search Engine,Displayobject,“我的脚本”在类别中搜索文件,然后必须显示该文件。示例:X用户正在PCgames类别中搜索Y游戏。X用户按下“搜索”按钮后,脚本必须显示在类别中找到的所有文件。但是我在剧本中有一些问题 search.php文件: <html> <body> <center> <font color="black" size="4"> <?php //define each directory here, the index starts with 0 ==

“我的脚本”在类别中搜索文件,然后必须显示该文件。示例:X用户正在PCgames类别中搜索Y游戏。X用户按下“搜索”按钮后,脚本必须显示在类别中找到的所有文件。但是我在剧本中有一些问题 search.php文件:

<html>
<body>
<center>
<font color="black" size="4">
<?php
//define each directory here, the index starts with 0 == all and so on.
$categorydir = array('/Category/All/', '/Category/PCGames/', '/Category/Console/', '/Category/Movies/', '/Category/Music/', '/Category/XXX/', '/Category/Windows/', '/Category/Linux/', '/Category/Software/', '/Category/Documents/');
//if option selected and its valid number
if (isset($_POST['category']))
 if(ctype_digit($_POST['category']) && isset($categorydir[$_POST['category']]))
if(array_key_exists($_POST['category'], $categorydir) && is_dir($categorydir[$_POST['category']])) //LINE 13
  $handle = opendir($categorydir[$_POST['category']]); //LINE 14
is_dir($categorydir[$_POST['category']]);
  $files = scandir($categorydir[$_POST['category']]);
  echo 'target directory not found';
echo 'Results of search:<br></br>';
foreach($files as $file){ //LINE 17
  echo($file);
}
?>
</font>
</center>
</body>
</html>
<html>
<head>
<title>DataHunters</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="header">
<h1 id="logo"><a href="index.html">DataHunters</a>
</h1>
</div>
<div id="navigation">
<ul>
<li><a class="active" href="index.html">Home</li></a>
<li><a href="chat.html">Chat</li></a>
<li><a href="contact.html">Contact</li></a>
<li><a href="http://www.forum.datahunters.ro">Forum</li></a>
</ul>
</li>
</div>
</body>
</html>

数据搜寻者
脚本给了我下一个错误:

注意:未定义的索引:C:\xampp\htdocs\search.php中的类别 第13行

注意:未定义的索引:在第13行的C:\xampp\htdocs\search.php中

注意:未定义的索引:C:\xampp\htdocs\search.php中的类别 第14行

注意:未定义的索引:在第14行的C:\xampp\htdocs\search.php中

警告:scandir():目录名在中不能为空 第14行的C:\xampp\htdocs\search.php目标目录不是 搜索结果:

警告:中为foreach()提供的参数无效 第17行的C:\xampp\htdocs\search.php


有什么帮助吗?

您的类别似乎没有定义。您需要一个表单来创建类别

将条件部分用大括号{}括起来,如下所示:

if (isset($_POST['category'])) {
    if(ctype_digit($_POST['category']) && isset($categorydir[$_POST['category']])) {
        if(array_key_exists($_POST['category'], $categorydir) && is_dir($categorydir[$_POST['category']])) {
            $handle = opendir($categorydir[$_POST['category']]); //LINE 14
            $files = scandir($handle);
            echo 'Results of search:<br></br>';
            foreach($files as $file){ //LINE 17
                echo($file);
            }
        } else {
            echo 'target directory not found';
    }
}
if(isset($\u POST['category'])){
if(ctype_数字($_POST['category'])和&isset($categorydir[$_POST['category'])){
如果(数组\键\存在($\ POST['category'],$categorydir)&&is\ dir($categorydir[$\ POST['category'])){
$handle=opendir($categorydir[$\u POST['category']]);//第14行
$files=scandir($handle);
回显“搜索结果:

”; foreach($files as$file){//第17行 echo($文件); } }否则{ 回显“未找到目标目录”; } }

我在这里也做了一些其他的改进。

方法必须是post或get?如果它在同一个脚本中,那么它是post,get Otherwise这只是一个示例,为您指明了正确的方向,不要尝试复制/粘贴此代码。我还没有测试过它。