- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用一个小脚本时遇到了一些问题,该脚本将文件从特定目录输出到表中,但当我在 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/
你好, 我在名为 content 的目录中有以下文件:仅 index.php、page1.php、page2.php 和 page3.php。 然后我有这个代码: $column = scandir
我正在尝试使用 scandir() 和 foreach() 获取匹配的文件数组。 当我运行 scandir() 时,它会返回所有文件列表。这里没问题。 现在在第二步中,当我执行 foreach sca
TIA。凭借我的 PHP 补救技能,我无法弄清楚为什么 scandir 不能按字母顺序自动排序。 (将文件夹组合在一起并按字母顺序排序以及将文件组合在一起并按字母顺序排序也很好,但这并不重要。)我错过
我需要帮助,如何按文件日期对下面的代码进行排序? $dir2 = "flash/$plk/img"; $plks2 = scandir($dir2); $plkss2 = array_d
我正在使用 scandir 来匹配目录中的某些文件。 match 函数采用 const struct dirent *dp 参数。 但我还需要传递另一个参数。当我尝试这样做时,编译会发出警告(不是错误
所以我试图构建一个脚本来扫描目录并返回用作背景的随机图像。 php 看起来是这样的: $dir = "views/img/bg/"; $dh = opendir($dir); while (fals
我想知道,我的 Scandir() 函数适用于 php $_GET 变量,因此该变量返回文件夹,但我遇到了问题,因为我不确定如何在存在错误时回显错误目录问题。 这是我收到的错误: Warning: s
我需要帮助,如何按文件日期对下面的代码进行排序? $dir2 = "flash/$plk/img"; $plks2 = scandir($dir2); $plkss2 = array_d
我试图列出有关指定目录中文件的信息,但收到内存故障核心转储错误。列出目录方法: int listdir(char *path) { struct dirent **dirlist; int n; c
我正在尝试通过子字符串过滤 scandir。我的函数可以正常工作,但只能使用预先确定的字符串。 int nameFilter(const struct dirent *entry) { if
我如何使用 scandir,以便它只用文件夹填充我的 struct dirent ** 名单? 最佳答案 您可以通过提供过滤函数来过滤要列出的实体,如果要将文件包含在列表中,该函数应返回非零值。 不幸
在我的程序中,我显示了一个文件列表。现在我正在使用带有内置 alphasort 函数的 scandir,但是我想根据创建日期进行排序。我写了自己的比较函数,但无论我测试多少,它都不起作用。这些项目以看
我希望我的脚本递归地 scandir, $files = scandir('/dir'); foreach($files as $file){ if(is_dir($file)){ echo
我在使用 scandir() 时遇到问题。我试图在我的云中子域下的页面上的 snaps 目录中显示文件。 这是我使用的 PHP。 $files = scandir('./snaps'); print_
我必须创建一个函数,将所有子文件夹列出到一个文件夹中。我有一个无文件过滤器,但该函数使用 scandir() 进行列表。这使得应用程序非常慢。是否有 scandir() 的替代方案,即使是非 nati
进行了一些搜索,但似乎无法找到我正在寻找的确切答案。 我想使用“scandir($dir)”提取带有编号文件名的文件,但要让它们正确排序。例如,文件名是: 1-something.ext 2-some
$contentdirectory = '/dead-wave/dead-wave_content'; $contentlaunch = scandir($contentdirectory
在UNIX® System Threads Reference ,在“线程安全”标题下是一个“不保证在所有 UNIX 系统上都是线程安全的”函数列表。函数 scandir() 不在此列表中,而 rea
我正在尝试使 scandir(); 函数超出其书面限制,我需要的不仅仅是它目前支持的 alpha 排序。我需要对 scandir(); 结果进行排序,以按修改日期排序。 我尝试了一些我在这里找到的解决
我遇到了 php glob 的一个特性功能,想知道到底发生了什么。 '; echo 'paths[0] = ' . $paths[0] .''; echo 'scandir count = ' . c
我是一名优秀的程序员,十分优秀!