在linux下将当前目录文件所有小写含目录名

ls | sed -n '/[A-Z]/s/.*/mv & \L&/e'

 

公司之前用的windows server 服务器  文件大小写都同样。  新迁移到centos 服务器上,发现有些上传图片是大写的扩展名。php

 1 <?php
 2 $path=$_SERVER['DOCUMENT_ROOT'].'/uploadfile';//要查找的目录
 3 echo $path;
 4 //var_dump(opendir($path));  //测试系统是否有权限执行
 5 //die('end');
 6 if($handle = opendir($path)){
 7     while(false !== ($file = readdir($handle))){
 8         if($file !='.' && $file !=".."){
 9             if(is_dir($path.'/'.$file)){
10                 nextdir($path.'/'.$file);
11             }else{
12             echo $file;    
13             }
14         }
15     }
16 }
17 /***循环目录***/
18 function nextdir($dir){
19     $handle=opendir($dir);
20     while(false !== ($file=readdir($handle))){
21         if($file !='.' && $file !='..'){
22             if(is_dir($dir.'/'.$file)){
23                 nextdir($dir.'/'.$file);
24             
25             }else{
26                 renamejpg($dir.'/'.$file);
27             }
28         }
29     }
30 }
31 /**修改文件名**/
32 function renamejpg($file){
33     if(substr($file,-3)=='JPG'){
34     file_put_contents('rename.log',$file."\n",FILE_APPEND);
35     rename($file,substr($file,0,-3).'jpg');
36     echo $file.'<br>';
37     }
38 }
39 
40 ?>

在本地调试是ok的,但在服务器上不行。发现是权限的问题。服务器php-fpm  是用nobody运行的,没有权限运行opendir.后新建一个php-fpm 用www账号运行。windows