$format ='jpg'; $path ='C:/Users/12759/Desktop/5.30.120.0'; $files = $this->getfile($path,$format); foreach( $files as $v ) { /* //$tv = basename($v); //dd($tv);*/ $aa = pathinfo($v); //dd($aa); //list($name,$ext) = explode('.',$tv); //$newname =$path.time().mt_rand(1,10000).'.'.$ext;*/ $newname = md5($aa['filename']).'.'.$aa['extension']; //dd($newname); /* if(rename($v,$newname)) { echo '成功将'.$v.'重命名'.$newname.'<br />'; }*/ rename($path.'/'.$v,$path.'/'.$newname); /*echo '成功将'.$v.'重命名'.$newname.'<br />'; */ echo "<span style='color:red'>".$v."</span>"."--------------".$newname."<br/>"; } public function getfile($dirname,$format) { $dirs = array(); $handle = opendir($dirname); while(($fn = readdir($handle))!==false){ if($fn!='.'&&$fn!='..'){ $curDir = $dirname.'/'.$fn; $path = pathinfo($curDir); $dirs[] = $path['basename']; } } return $dirs; }
The above introduces the batch renaming of PHP files, including the contents of PHP files and batch renaming. I hope it will be helpful to friends who are interested in PHP tutorials.