display a file on page using php

独自空忆成欢 提交于 2019-12-13 08:09:00

问题


I made a script that searches in a category for a file. My issue is: after searching the script doesn't display results of the search. Example: I'm searching for a game like :-? AC3. After search the script doesn't display any result. Some help?

<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']])){
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){
  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>

回答1:


I believe the problem is that you're opening a directory and not doing anything with the handle. You might instead try using scandir() which will result in an array of the files in the directory, instead of a directory object.

Edit: you might try something like this:

...
is_dir($categorydir[$_POST['category']])){
  $files = scandir($categorydir[$_POST['category']]);
}else{
  echo 'target directory not found';
}
echo 'Results of search:<br></br>';
foreach($files as $file){
  echo($file);
}


来源:https://stackoverflow.com/questions/15120727/display-a-file-on-page-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!