Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过php读取压缩文件的文件名_Php_Zip_Filenames - Fatal编程技术网

通过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

我正在尝试编写一个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中也可以吗?我如何处理这样的问题

下面是我用来获取服务器上具有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-目前有一个非常类似的问题,您可以将其用作参考。