php开发技巧

php 使用 Maatwebsite\Excel上传excel文

2020-06-02  本文已影响0人  顶尖少爷

直接上代码 上传excel 保存处理为json文件

       $fileName="";
        if(!empty($request->file("excel"))){
            //base_path("public/storage/excel/demo.xlsx")
            $excelUrl =$request->file("excel")->store("/public/storage/excel");
            $items=Excel::toArray(new GameAppOptionImportRepository(),$excelUrl,"","");
            foreach ($items[0] as $key=>$item){
                if($key==0) continue;
                $eventName = trim($item[0]);

                if(!empty($item[1])){
                    $data[$eventName]["adjust"]=trim($item[1]);
                }

                if(!empty($item[2])){
                    $data[$eventName]["re_name"]=trim($item[2]);
                }
            }

            $str = json_encode($data);
            $fileName = "/storage/json/".$appId."_".$request->get("version").".json";
            $jsonUrl = base_path("public".$fileName);
            file_put_contents($jsonUrl,$str);
        }
上一篇 下一篇

猜你喜欢

热点阅读