以下是旧版本教程,为了兼容laravel6.0 作者有新开发地址
https://github.com/madnest/madzipper
使用以下方法可以将压缩包内容 转存到指定目录 Madzipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/^(?!.*test\.php).*$/i');
主要用以下逻辑获取plist文件中的
$ipaInfo['CFBundleIcons']['CFBundlePrimaryIcon']['CFBundleIconFiles'] logo前缀
// 遍历zip包中的Info.plist文件 $zipFiles = Zipper::make($this->targetFile)->listFiles('/Info\.plist$/i'); $matched = 0; if ($zipFiles) { foreach ($zipFiles as $k => $filePath) { // 正则匹配包根目录中的Info.plist文件 if (preg_match("/Payload\/([^\/]*)\/Info\.plist$/i", $filePath, $matches)) { $matched = 1; $this->app_folder = $matches[1]; // 将plist文件解压到ipa目录中的对应包名目录中 Zipper::make($this->targetFile)->folder('Payload/'.$this->app_folder)->extractMatchingRegex(storage_path('app/public/'.env('APP_ENV', 'local').'/upload/plist/'.$this->app_folder), "/Info\.plist$/i"); // 拼接plist文件完整路径 $fp = storage_path('app/public/'.env('APP_ENV', 'local').'/upload/plist/'.$this->app_folder.'/Info.plist'); // 获取plist文件内容 $content = file_get_contents($fp); // 解析plist成数组 $ipa = new \CFPropertyList\CFPropertyList(); $ipa->parse($content); $ipaInfo = $ipa->toArray(); // ipa 解包信息 $this->ipa_data_bak = json_encode($ipaInfo); // 包名 $this->package_name = $ipaInfo['CFBundleIdentifier']; // 版本名 $this->version_name = $ipaInfo['CFBundleShortVersionString']; // 版本号 $this->version_code = str_replace('.', '', $ipaInfo['CFBundleShortVersionString']); // 别名 $this->bundle_name = $ipaInfo['CFBundleName']; // 显示名称 $this->display_name = $ipaInfo['CFBundleDisplayName']; } } }
然后使用前缀匹配压缩包文件 即可
preg_match("/Payload\/([^\/]*)\/Info\.plist$/i", $filePath, $matches
使用前提:laravel 版本必须大于 5
1、使用 composer 引入
composer require chumper/zipper
2、配置 app/config/app.php
'providers'=>[
Chumper\Zipper\ZipperServiceProvider::class
]
'aliases' => [
'Zipper' => Chumper\Zipper\Zipper::class
]
3、压缩文件
***** 必须使用 use 引文文件
use Chumper\Zipper\Zipper;
$number=1;
$zip=new Zipper();
$newName='group_'.$number.'.zip';
$zip->make(public_path('vdieoZip/'.$newName))->add($res);
$zip->close();
return response()->download(public_path('vdieoZip/'.$newName));
4、解压文件
***** 必须使用 use 引文文件
use Chumper\Zipper\Zipper;
$zip = new Zipper();
$zip->make(压缩的文件目录)->extractTo(压缩之后的目录);
5:遍历文件打包至压缩包
$files = Array();
foreach ($student as $key => $data) {
if ($data->photopath != null) {
$check = glob(storage_path('photo/' . $data->photopath));
$files = array_merge($files, $check);
}
}
Zipper::make(storage_path() . '/systemImg/' . $name)->add($files)->close();
6:读取压缩包文件
Zipper::make( storage_path() . '/photo/photos')->extractTo(storage_path('temp'));
$zip = new \ZipArchive();//方法2:流处理,新建一个ZipArchive的对象
$logFiles = Zipper::make($path)->listFiles('/\.png$/i');
if ($zip->open($path) === TRUE) {
foreach ($logFiles as $key) {
$stream = $zip->getStream($key);
$str = stream_get_contents($stream); //这里注意获取到的文本编码
$name = iconv("utf-8", "gb2312//IGNORE", $key);
file_put_contents(storage_path() . '\temp\\' . $name, $str);
}
} else {
return '{"statusCode":"300", "message":"上传失败,请检查照片"}';
}
参考的是laravel社区文章
https://learnku.com/articles/16000
https://blog.csdn.net/weixin_42188216/article/details/100518495
https://returnc.com/detail/3706