$dirName = 'D:\WXWork\1688856202390297\Cache\File\2023-06\汽配城图片\汽配城图片'; $temp_list = scandir($dirName); foreach ($temp_list as $file) { //排除根目录 if ($file != ".." && $file != ".") { if (is_dir($dirName . "/" . $file)) { //子文件夹,进行递归 $list[$file] = scandirFolder($dirName . "/" . $file); } else { //根目录下的文件 if (strpos($file, '.jpeg')) { $list[] = [ "path" => $dirName . "/" . $file, 'name' => str_replace(".jpeg", "", $file) ]; } if (strpos($file, '.png')) { $list[] = [ "path" => $dirName . "/" . $file, 'name' => str_replace(".png", "", $file) ]; } } } } $uploadService = app()->make(UploadService::class); foreach ($list as $item) { $res = $uploadService->upload(1,$item['path']); $id = CarPartsMarket::query() ->where('name', $item['name']) ->update(['avatar' => $res]); }
标签:文件,dirName,name,list,item,file,path,操作,PHP From: https://www.cnblogs.com/yyyyyyyyx/p/17502094.html