Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP目录内容-计数错误&;删除某些文件_Php_Arrays - Fatal编程技术网

PHP目录内容-计数错误&;删除某些文件

PHP目录内容-计数错误&;删除某些文件,php,arrays,Php,Arrays,我现在有一个无刺激上传器的代码。它还显示包含文件夹的内容,但是echo“$indexCount files”返回文件数+2,但我看不出变量是如何到达这个数字的 此外,我希望表不显示页面本身(index.php)和错误日志。我尝试了这样的逻辑:如果文件名是x或y,那么转到下一个文件,但我无法让它工作 谢谢 <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method=

我现在有一个无刺激上传器的代码。它还显示包含文件夹的内容,但是
echo“$indexCount files
返回文件数+2,但我看不出变量是如何到达这个数字的

此外,我希望表不显示页面本身(index.php)和错误日志。我尝试了这样的逻辑:
如果文件名是x或y,那么转到下一个文件
,但我无法让它工作

谢谢

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Please choose a file: <input name="file" type="file" /><br />
<input type="submit" value="Upload" /></form>


<?php 

if (!empty($_FILES["file"]))
{
    if ($_FILES["file"]["error"] > 0)
       {echo "Error: " . $_FILES["file"]["error"] . "<br>";}
    else
       {echo "Stored file:".$_FILES["file"]["name"]."<br/>Size:".($_FILES["file"]["size"]/1024)." kB<br/>";
       move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);
       }
}

    // open this directory 
    $myDirectory = opendir(".");
    // get each entry
    while($entryName = readdir($myDirectory)) {$dirArray[] = $entryName;} closedir($myDirectory);
    $indexCount = count($dirArray);
        echo "$indexCount files<br/>";
    sort($dirArray);

    echo "<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks><TR><TH>Filename</TH><th>URL</th><th>Wiki Syntax</th></TR>\n";

        for($index=0; $index < $indexCount; $index++) 
        {
            if (substr("$dirArray[$index]", 0, 1) != ".")
            {
            echo "<TR>
            <td><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>
            <td>http://www.example.com/$dirArray[$index]</td>
            <td><input type='text' value='[[http://www.example.com/$dirArray[$index]|$dirArray[$index]]' /></td>
                </TR>";
            }
        }
    echo "</TABLE>";
    ?>

它们是
目录。您无法看到它们,因为
substr($dirArray[$index]”,0,1)!=“
为它们返回
false


while
循环中,您可以过滤它们,或者只需取消设置
$dirArray

的前两个元素。它返回
文件数+2
的原因可能是
readdir
调用计数以及
目录项,它们同时引用当前目录和父目录。

太好了,我没有想到隐藏的文件。然后如何从表数据中删除index.php和error_log?谢谢Pamil。如何过滤特定文件(index.php和error\u log)?我不知道如何将它们添加到
if(substr($dirArray[$index]”,0,1)!=“)
如果你不想查看这些,你可以这样做:
$filters=array(“index.php”,“error_log”,“,”);if(false==in_array($dirArray[$index],$filters){/*不显示*/}。否则{/*显示*/}