在带有centos 7和php版本7.2的laravel中上传excel时找不到ZipArchive类

时间:2018-12-30 13:03:30

标签: ziparchive

我正在尝试将Excel数据上传到MySQL DB。但我收到错误类“ ZipArchive”,但未找到。我正在使用Linux centos 7和PHP 7.2

 code:  
 public function uploadExcel(Request $request){
        $this->validate($request, array(
            'file'      => 'required'
        ));

        if($request->hasFile('file')) {
            $extension = File::extension($request->file->getClientOriginalName());
            if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") {
                $path = $request->file->getRealPath();
                $data = Excel::load($path, function($reader) {
                })->get();
                if(!empty($data) && $data->count()){
                    foreach ($data as $key => $value) {
                        $insert[] = ['title' => $value->title, 'description' => $value->description];
                    }
                    if(!empty($insert)){
                        DB::table('items')->insert($insert);
                        //  dd('Insert Record successfully.');
                    }
                }
                echo "Data".$insert;
                exit;
            } else {
                Session::flash('error', 'File is a '.$extension.' file.!! Please upload a valid xls/csv file..!!');
                return back();
            }
        }
    }

    But I am getting this error

    Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
    Class 'ZipArchive' not found

0 个答案:

没有答案