-1

私のスクリプトは、ファイルのカテゴリを検索し、ファイルを表示する必要があります。例: 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>

そして、スクリプトは私に次のエラーを与えます:

注意: 未定義のインデックス: 13 行目の C:\xampp\htdocs\search.php のカテゴリ

注意: 未定義のインデックス: C:\xampp\htdocs\search.php の 13 行目

注意: 未定義のインデックス: C:\xampp\htdocs\search.php の 14 行目のカテゴリ

注意: 未定義のインデックス: C:\xampp\htdocs\search.php の 14 行目

警告: scandir(): ディレクトリ名を C:\xampp\htdocs\search.php で空にすることはできません 14 行目のターゲット ディレクトリが見つかりません 検索結果:

警告: C:\xampp\htdocs\search.php の 17 行目の foreach() に無効な引数が指定されました

手助け?

4

2 に答える 2

0

あなたのカテゴリは定義されていないようです。カテゴリを作成するにはフォームが必要です。

于 2013-02-27T20:56:53.223 に答える
0

次のように、条件部分を中かっこ {} で囲みます。

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';
    }
}

ここでもいくつかの改善を行いました。

于 2013-02-27T20:57:59.243 に答える