Now there is such a requirement that you need to rename all the files uploaded in the database. You can use the following method to quickly process
ini_set("max_execution_time", 0); /*使用chunk分块处理数据*/ DB::table('xxx')->orderby('id')->where('imageurl','<>','')->chunk(100,function($rows) { // $list=[]; foreach ($rows as $row) { $fileInfo=pathinfo($row->imageurl); $newFileName='.'.$fileInfo['dirname'].'/'.$fileInfo['filename'].time().'.'.$fileInfo['extension']; echo '正在处理:'.$newFileName.' id:'.$row->id.'<br/>'; if(file_exists('.'.$row->imageurl)) { rename('.'.$row->imageurl,$newFileName); } echo var_dump(['id'=>$row->id,'imageurl'=>substr($newFileName,1)]); $content=ob_get_contents(); sleep(1); DB::table('km')->where('id',$row->id)->update(['imageurl'=>substr($newFileName,1)]); } });