1: Add this package to the list of required packages in composer.json
"chumper/zipper": "1.0.x"
2: command line execution
composer update
3: Configure app/config/app.php
add to providers Chumper\Zipper\ZipperServiceProvider::class add to aliases 'Zipper' => Chumper\Zipper\Zipper::class
4: Traverse the file and pack it into a compressed package
$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();
5: Read the compressed package file
Zipper::make( storage_path() . '/photo/photos')->extractTo(storage_path('temp')); $zip = new \ZipArchive();//Method 2: Stream processing, create a new ZipArchive object $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); //Note the obtained text encoding here $name = iconv("utf-8", "gb2312//IGNORE", $key); file_put_contents(storage_path() . '\temp\\' . $name, $str); } } else { return '{"statusCode":"300", "message":"Upload failed, please check the photo"}'; }