如何在Laravel 6中提取zip文件

时间:2019-09-16 06:31:03

标签: php laravel zip

我正在运行最新的Laravel 6,并希望上传和提取ZIP文件。我尝试使用作曲器压缩器/拉链-但似乎它还与Laravel 6不兼容。因此,我尝试使用PHP zipArchive。

我要尝试的过程的代码是:

props

该zip文件已成功上传到正确的位置。

$ target_path的示例为const ProductsGridItem = props => { const { result: {_source: source}, handleOpen } = props; return ( <ProductCard handleOpen={handleOpen} ProductName={source.productName} ProductGuid={source.productGuid} Key={source.productGuid} ProductStatus={source.status} DecimalPrecision={decimalValue} IsActive={source.isActive} Image={source.imageName} ProductCode={source.productCode} MinPrice={source.minPrice} Ratings={source.ratings} CurrencySymbol={source.currencySymbol} SupplierGuid={source.supplierGuid} Type="grid" ListBucketDetails={basketDetails} WishListDetails={wishListDetails} CompanyName={source.companyName} BuyingWindowStatus={source["buyingwindowstatus.raw"]} NewArrival={source["newarrival_raw.raw"]} /> ); };

但是,我得到一个错误:

  

SplFileInfo :: getSize():/ tmp / php59z5uT的统计信息失败

我已经检查了php.ini文件,其大小和内存远高于我要使用的700kb测试zip文件。

当我按下 $docfileext1 = $request->file('czipfile')->getClientOriginalExtension(); $random_filename1 = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz123"), -5); $newfilename1 = $random_filename1.'.'.$docfileext1; //First check this is a ZIP file if ($docfileext1 <> 'zip') { return back(); //->witherrors('this is not a ZIP file. Please select a zip file'); } $request->file('czipfile')->move( base_path() . '/storage/app/'.$oid.'/courses/'.$inscourse, $newfilename1 ); //Now unzip $target_path = base_path() . '/storage/app/' .$oid. '/courses/'. $inscourse.'/'.$newfilename1; $extract_path = base_path() . '/storage/app/' .$oid. '/courses/'. $inscourse.'/'; $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo($extract_path); $zip->close(); } 功能时弹出哪个窗口。

关于我在这里做错什么的任何想法,还是有更好的方法?衷心感谢。

1 个答案:

答案 0 :(得分:0)

我也在寻找这个方法,但我发现了这种方法,我不是专家,但这确实可以做到

使用:vipsoft/unzip

我的代码就是这样

if(isset($request->zipfile)){
   $unzipper  = new Unzip();
   $file = $request->zipfile->store('public'); //store file in storage/app/zip
   $filenames = $unzipper->extract(storage_path('app/'.$file),storage_path('app/public'));
   //extract the files in storage/app/public 
   dd($filenames); //show file names
}

我希望这会有所帮助