【发布时间】:2016-04-14 08:06:33
【问题描述】:
我的脚本在类别中搜索文件,然后必须显示该文件。示例: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():目录名不能为空 C:\xampp\htdocs\search.php 在第 14 行目标目录不是 found 搜索结果:
警告:为 foreach() 提供的参数无效 C:\xampp\htdocs\search.php 第 17 行
一些帮助?
【问题讨论】:
标签: php file-io search-engine displayobject