php函数批量修改文件后缀名
例子,php函数批量修改文件后缀名的代码。
 
复制代码 代码示例:
<?php 
function foreachDir($path){ 
  $handle=opendir($path); 
  if($handle){ 
    while (false !== ($file = readdir($handle))) { 
       if($file!="." && $file!='..'){ 
          if(is_dir($path.$file)){ 
             echo $path.$file."<br/>"; 
             foreachDir($path.$file); 
                }else{ 
                echo "--".$path."/".$file."<br/>"; 
                $ext = strripos($file,'.'); 
                $aaa = substr($file,0,$ext); 
                rename($path.'/'.$file,$path.'/'.$aaa.'.JPG'); 
// die(); 
} 
} 
} 
return false; 
}
}
调用,批量修改文件后缀名:
 
复制代码 代码示例:
foreachDir('D:xampphtdocsTNF2');