2015-04-03 35 views
0

列出文件夹时,这是我写的代码,但我总是看到的文件夹名称前这3个点显示出来:3点在HTML源代码PHP

<?php 

$dir=new DirectoryIterator("wallpapers"); 


while ($dir->valid()) 
    { 
    $file=$dir->current(); 
echo $file->getFilename(); 
echo "<br>"; 
$dir->next(); 
} 

?> 
+0

'foreach($ folder作为$ dir){}'也许? – Daan 2015-04-03 14:56:43

+0

好的。但我如何使用当前文件夹来设置它? – 2015-04-03 14:59:52

回答

0

你要善于去用这个

$dir = "/etc/php5/*"; 


foreach(glob($dir) as $file) 
{ 
    echo "filename: $file : filetype: " . filetype($file) . "<br />"; 
} 
+0

嗯,我自己想出来了,但现在它显示了三个点,然后显示文件夹列表。这里是代码: 为什么我看到3个点“。”。然后在html源代码中“..”? 谢谢大家! <?php $ dir = new DirectoryIterator(“wallpapers”); while($ dir-> valid()) { $ file = $ dir-> current(); echo $ file-> getFilename(); echo“
”; $ dir-> next(); } ?> – 2015-04-03 15:38:13

+0

的。而..文件夹是隐藏文件夹。你需要建立一个你不想看到的文件夹的忽略列表。 – Unex 2015-04-03 15:40:15

+0

尝试使用realpath()函数。它会解决。或..或./等。这里是文档http://php.net/manual/en/function.realpath.php – Capri82 2015-04-08 19:09:55