How To Extract ZIP File And Store Data In Laravel

How to extract ZIP files using ZanySoft/Laravel-zip package and then store data in the database?

Well, there is PHP ZipArchive to do so you can use it. Laravel package ZanySoft/Laravel-zip makes it simple and automated.

How To Create ZIP File And Download In Laravel

ZanySoft/Laravel-zip

There are a number of other ZIP file extractor packages that do the same ZanySoft package will make you upload, extract, create, download, and add files/folders to the ZIP to download.

So you don’t only extract but get the ability to create, and add files and folders using this package.

You can list the uploaded files and save them to the database. $zip->listFiles();

$zip = new Zip();
$file = $request->file('zipfile');
$zip = Zip::open($file);
$zip->extract(public_path('zipfolder'));
$zip->close();

This is how you upload and extract ZIP files. The file will be saved to the folder mentioned in zipfolder under the public folder. You can choose the storage path instead.

$zip = new Zip();
$file = $request->file('zipfile');
$zip = Zip::open($file);
$zip->extract(public_path('zipfolder'));
foreach ($zip->listfiles() as $filename) {
       # Loop will run number of times as the number of files in the ZIP files
}
$zip->close();

Related Posts