zoukankan      html  css  js  c++  java
  • 在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."
    ",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帐号运行。

  • 相关阅读:
    【REST详述及RESTful规范】
    【Vue CLI】从安装到构建项目再到目录结构的说明
    【Webpack】
    【npm】安装、搭建独立项目环境
    【Node.js安装步骤】
    【Vue路由系统详述】
    【Python实现图片验证码】
    【Vue实例生命周期】
    【Vue组件系统】
    Java实现几种常见排序方法
  • 原文地址:https://www.cnblogs.com/linuxOS/p/3975310.html
Copyright © 2011-2022 走看看