0

大家好,我正在尝试阅读一个名为 people 的目录,该目录充满了php,html,png,jpeg其他格式。我正在尝试过滤我想要的文件phphtml文件,然后将它们回显。

这是我的尝试,因为它没有echo任何文件,所以没有成功:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Khviii ICT</title>
</head>

<body>
<div align="center" ><h1>Welcome to KHVIII ICT</h1></div>
<?php
$dir="/people";
$allowed_view= array("php","html");
$files=scandir($dir);
foreach ($files as $file)
{
        $filexplosion=strtolower(end(explode('.',$file)));
    if (in_array($allowed_view,$filexplosion)) 
        {
    echo $file;
    } 
}
?>
</body>
</html>
4

3 回答 3

0

尝试这个:

$files=scandir($dir);
echo "I have found " . count($files) . " files<br>"; // Are you sure there are files found?
foreach ($files as $file)
{
$filexplosion = substr($file, strrpos($file, "."));
echo $filexplosion; // just to check if you're getting the right value
if (in_array($allowed_view,$filexplosion)){
  echo $file;
} 
于 2013-06-23T21:39:59.490 回答
0

目录路径不正确且 in_array 参数不按顺序排列。更正后的php代码如下:

    $dir = __DIR__ . "/people";
    $allowed_view = array("php", "html");
    $files = scandir($dir);
    foreach ($files as $file) {
        $filexplosion = strtolower(end(explode('.', $file)));
        if (in_array($filexplosion, $allowed_view)) {
            echo $file;
        }
    }
于 2013-06-23T21:35:40.850 回答
0

经过几次我已经解决了我正在使用gelb()。这是代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>khvii index</title>
</head>

<body>
<?php
foreach (glob("people/"."*.php",GLOB_BRACE) as $filename) {
    $phpexplode = end(explode("/",$filename));
    echo'<a href="'.$filename.'"><input type="button" value="'.$phpexplode.'"></a><br />';
}
foreach (glob("people/"."*.html",GLOB_BRACE) as $filename) {
    $htmlexplode = end(explode("/",$filename));
    echo'<a href="'.$filename.'"><input type="button" value="'.$htmlexplode.'"></a><br />';
}
?>
</body>
</html>
于 2013-06-24T17:59:36.563 回答