小编Jim*_*mmy的帖子

如何在 Laravel 6 中解压 zip 文件

我正在运行最新的 Laravel 6 并想要上传并解压 ZIP 文件。我尝试使用 Composer chumper/zipper - 但似乎它与 Laravel 6 不兼容。所以我尝试使用 PHP zipArchive。

我正在尝试的过程的代码是:

                    $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(); …
Run Code Online (Sandbox Code Playgroud)

php zip laravel

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

laravel ×1

php ×1

zip ×1