在linux下将当前目录文件全部小写含目录名

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

 

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

 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帐号运行。

转载于:https://www.cnblogs.com/linuxOS/p/3975310.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值