gpt4 book ai didi

php - 从 scandir() 隐藏 .DS_store

转载 作者:行者123 更新时间:2023-12-04 12:49:54 24 4
gpt4 key购买 nike

我在使用一个小脚本时遇到了一些问题,该脚本将文件从特定目录输出到表中,但当我在 Mac 上运行此应用程序时,它会输出烦人的 .DS_store 文件。

这是我要放置的脚本 - 我尝试了各种方法,要么完全停止脚本工作,要么无效。

<?php

echo '<table>';

$dir = 'archive/';
$files = scandir($dir, 0);
for($i = 2; $i < count($files); $i++)
echo '<tr>
<td>' . $files[$i]. '</td>
<td><a href="' . $files[$i]. '" download><button>Download</button></a>
<a href=""></a></td>
</tr>';

echo '</table>';

?>

最佳答案

您可能希望忽略所有以“.”开头的文件

._whatever:这些文件是在本身不支持 HFS 的卷上创建的。

.Trash : 用于存放扔进垃圾箱但还没有被删除的文件。

.Spotlight-V100 : 存储 Spotlight 的元数据索引和索引规则。

<?php

echo '<table>';

$dir = 'archive/';
$files = scandir($dir, 0);
for($i = 2; $i < count($files); $i++)
if (preg_match("/^[^\.].*$/", $files[$i])) {
echo '<tr>
<td>' . $files[$i]. '</td>
<td><a href="' . $files[$i]. '" download><button>Download</button></a>
<a href=""></a></td>
</tr>';
}
echo '</table>';
?>

关于php - 从 scandir() 隐藏 .DS_store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40527632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com