2012-08-22 67 views
0

我让用户使用打开并读取目录的下拉菜单从目录中选择特定文件。打印目录列表时删除某些项目

目录列表中有一些项目不应该在那里。像

. 
.. 
.com.apple.timemachine.supported 
.DS_Store 

我将如何去除这些?他们看起来像目录命令或信息什么的。用户不应该能够选择这些,尽管我不认为他们会这样做。

这里是我正在使用的代码来读取目录,并将项目打印到下拉列表中。

<div id='fileOpen'>  
<? 
    $pathToImages = 'images/'; 
    $pathToVolume = '/Volumes/storage/spots_in/'; 

    if ($handle = opendir($pathToVolume)) { 
?> 
    <span class='locate'>Locate master file:</span> 
    <select id='file' name='file'> 
<? 
    while (false !== ($entry = readdir($handle))) { 
     echo "<option>"; 
     echo "$entry\n"; 
     echo "</option>"; 
    } 
    closedir($handle); 
} 
</div> 

回答

1

我用这个

if (!preg_match("/^\./","$entry\n")) 
+0

完美。这工作完美。感谢您的快速响应! – patricko

+0

不用担心。如果你只想要文件,你也可以做一个is_file检查,但preg对我来说工作正常。 –

0
while (false !== ($entry = readdir($handle))) { 
    if (substr($entry, 0, 1) == '.') { 
     continue; 
    } 

    /* Other stuff 
}