通过php读取压缩文件的文件名
我正在尝试编写一个php脚本,它将回显文件夹中压缩文件的文件名。每个档案都包含一个文件。 例如,我在服务器上有:通过php读取压缩文件的文件名,php,zip,filenames,Php,Zip,Filenames,我正在尝试编写一个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 f
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中也可以吗?我如何处理这样的问题
下面是我用来获取服务器上具有FolderName的文件名的脚本(如果还提供文件修改日期和大小),但没有提供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");
}
}
您可能想使用ZipArchive-目前有一个非常类似的问题,您可以将其用作参考。