如何在不在服务器上解压缩的情况下检查 zip 文件是否包含所有图像文件
How to check if zip file contains all images file without unzipping on server
我想检查zip中的所有文件是否都是图片,到目前为止我想出了这个解决方案
$zip = new ZipArchive;
$res = $zip->open('CQN.zip');
if ($res) {
$legitImage=explode('.',$zip->statIndex(0)['name']);
if($legitImage[1] !='jpg')
{
// just stop processing
}
}
我只是想循环 zip 中的每个文件以获取图像,如果找不到图像而不只是回显错误
<?php
$za = new ZipArchive();
$za->open('theZip.zip');
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$ext = pathinfo(( basename( $stat['name'] ) . PHP_EOL ), PATHINFO_EXTENSION);
echo $ext;
echo "<br>";
}
?>
我正在从 FOR 循环中添加 $ext 数组,将数组放在循环外,您可以根据需要使用该数组进行操作。
<?php
$array = array();
$za = new ZipArchive();
$za->open('theZip.zip');
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$ext = pathinfo(( basename( $stat['name'] ) . PHP_EOL ), PATHINFO_EXTENSION);
$array[] = $ext;
}
print "For: ".count($array)."<br />";
print_r($array);
foreach ($array as $value) {
echo $value . "<br />";
}
?>
我想检查zip中的所有文件是否都是图片,到目前为止我想出了这个解决方案
$zip = new ZipArchive;
$res = $zip->open('CQN.zip');
if ($res) {
$legitImage=explode('.',$zip->statIndex(0)['name']);
if($legitImage[1] !='jpg')
{
// just stop processing
}
}
我只是想循环 zip 中的每个文件以获取图像,如果找不到图像而不只是回显错误
<?php
$za = new ZipArchive();
$za->open('theZip.zip');
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$ext = pathinfo(( basename( $stat['name'] ) . PHP_EOL ), PATHINFO_EXTENSION);
echo $ext;
echo "<br>";
}
?>
我正在从 FOR 循环中添加 $ext 数组,将数组放在循环外,您可以根据需要使用该数组进行操作。
<?php
$array = array();
$za = new ZipArchive();
$za->open('theZip.zip');
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$ext = pathinfo(( basename( $stat['name'] ) . PHP_EOL ), PATHINFO_EXTENSION);
$array[] = $ext;
}
print "For: ".count($array)."<br />";
print_r($array);
foreach ($array as $value) {
echo $value . "<br />";
}
?>