[PHP] 获取指定目录下的文件和文件夹,并将文件和文件夹分别以逗号间隔输出 →→→→→进入此内容的聊天室

来自 , 2019-05-14, 写在 PHP, 查看 104 次.
URL http://www.code666.cn/view/38a77aa4
  1. <?php
  2. /*
  3.  * 获取指定目录下的文件和文件夹,并将文件和文件夹分别以逗号间隔输出。
  4.  */
  5. function getAllFilesAndDirs($path){
  6.     $files = '';
  7.     $dirs = '';
  8.     $alls = scandir($path);
  9.  
  10.     if(!empty($alls)){
  11.         foreach ($alls as $all){
  12.             if($all != "." && $all != ".."){
  13.                 if(is_file($path.'/'.$all)){
  14.                     if(empty($files)){
  15.                         $files .= $all;
  16.                     }else{
  17.                         $files .= ",".$all;
  18.                     }
  19.                 }
  20.                 if(is_dir($path.'/'.$all)){
  21.                     if(empty($dirs)){
  22.                         $dirs .= $all;
  23.                     }else{
  24.                         $dirs .= ",".$all;
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.     }else{
  30.         echo "input param is not a valid path.";
  31.     }
  32.     return "dirs: ".$dirs."   files: ".$files;
  33. }
  34. //获取当前文件夹下的cleanAD中的文件和文件夹。
  35. echo getAllFilesAndDirs("cleanAD");
  36. ?>

回复 "获取指定目录下的文件和文件夹,并将文件和文件夹分别以逗号间隔输出"

这儿你可以回复上面这条便签

captcha