我试图编写一个php脚本来回显文件夹中压缩文件的文件名。每个档案都有一个档案。 例如我在服务器上:
file1.zip containing zipped file with name file1.exe
file2.zip containing zipped file with name file1.txt
folder1/file3.zip containing zipped file with name file1.html
我希望脚本能够回显列表:
file1.exe
file1.txt
folder1/file1.html
甚至可以在PHP中使用吗?我该如何解决这个问题?
这是我用来在服务器上获取带有foldernames的文件名的脚本(如果还提供文件修改日期和大小)什么是不给我的是zip文件包含的文件的文件名:
// Create recursive dir iterator which skips dot folders
$dir = new RecursiveDirectoryIterator('./patchfolder',
FilesystemIterator::SKIP_DOTS);
// Flatten the recursive iterator, folders come before their files
$it = new RecursiveIteratorIterator($dir,
RecursiveIteratorIterator::SELF_FIRST);
// Maximum depth is 1 level deeper than the base folder
$it->setMaxDepth(1);
// Basic loop displaying different messages based on file or folder
foreach ($it as $fileinfo) {
if ($fileinfo->isFile()) {
echo str_replace("./patchfolder/","",$fileinfo.",". date ("Y-m-d H:i:s",filemtime($fileinfo)).",".filesize($fileinfo)."\n");
}
}