【发布时间】:2016-06-28 21:28:58
【问题描述】:
我看到了一些类似的问题,但这些并不是我想要的。我正在寻找比以下代码更好的方式来浏览文件和目录:
$currentdir = (isset($_GET['current']) && !empty($_GET['current'])) ? $_GET['current'] : '.';
if(!file_exists($currentdir)) {
echo "There is no such directory (".$currentdir.")";
$currentdir = '.';
}
$dirs = [];
$others = [];
foreach (new DirectoryIterator($currentdir) as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isDir()) {
array_push($dirs, $fileInfo->getFilename());
} else {
array_push($others, $fileInfo->getFilename());
}
}
echo("<h3>Directories:</h3>");
foreach($dirs as $dir) {
echo "<a href='?current=$dir'>".$dir."</a><br>";
}
echo("<h3>Files:</h3>");
foreach($others as $other) {
$mod_date=date("d/m/Y H:i", filemtime($other));
$size = filesize($other);
echo "$other $mod_date $size<br>";
}
我将来想要实现的是能够在目录中移动(这意味着我需要为它们提供完整的路径)并能够对它们执行一些基本操作 - 复制、读取等。那么谁能给我一个很好的方法,也许是一个框架?
此外,在这段代码中,通过子目录移动并不顺利。我应该将父目录路径存储在某处还是以完全不同的方式重写它?
【问题讨论】:
-
您的问题非常广泛,包含很多“假设”。我建议你尝试构建一些东西并在遇到困难时提出具体问题,或者只是谷歌搜索“PHP 文件管理器”(你的两个标签),然后从 Source Forge 下载完整的 PHP 文件管理器,你会得到第一个结果。跨度>
标签: php file-manager