使用php在页面上显示文件 [英] display a file on page using php

查看:88
本文介绍了使用php在页面上显示文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个脚本,该脚本在类别中搜索文件.我的问题是:搜索脚本后不显示搜索结果.示例:我正在搜索类似:-?的游戏AC3.搜索后,脚本不会显示任何结果.一些帮助?

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>

推荐答案

我相信问题在于您正在打开目录,而对句柄没有任何处理.相反,您可以尝试使用scandir(),这将导致目录中的文件数组而不是目录对象.

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.

您可以尝试执行以下操作:

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

这篇关于使用php在页面上显示文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆