栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

PHP获取目标路径的文件目录

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP获取目标路径的文件目录

   PHP获取目标路径(图片目录)的文件目录的原生代码,写出来后发现还有很大的优化空间,但由于是练手的作品没再深入修改,但这几天都有同学问我这个问题,所以决定开通博客,并在此献丑,若有更优方法,也请各位不吝斧正!

   闲话少说,代码如下:

';        $str .= $this -> Dloop($val,$newpath,$spaces,$spaces);                       }      else{        //$str .= '这里写入树';        if(stripos($key,'.jpg')||stripos($key,'.jpeg')){          $fn = '.$space.'px;">'.$key;        }        elseif(stripos($key,'.gif')){          $fn = '.$space.'px;">'.$key;        }        elseif(stripos($key,'.png')){          $fn = '.$space.'px;">'.$key;        }        else{          $fn = '.$space.'px;">'.$key;        }        $kb = round(filesize($path.$key)/1024)."k";        $str .= '';      }    }  return $str;   }}?>

class files{  protected function refiles($path){    if(file_exists($path)){      $ref = scandir($path,1);      foreach($ref as $val){        if($val=='.'||$val=='..'){          continue;        }        $arr[$val] = is_dir($path.$val)?'folder':'img';      }    }    else{      $arr = false;    }    return $arr;  }  protected function reall($arr,$path){    foreach($arr as $key =>$val){      if($val == 'folder'){        $newpath = $path.$key."/";        $temps = $this->refiles($newpath);        if($temps){          $newtemp = $this->reall($temps,$newpath);          $arr[$key] = $newtemp;        }        else{          $arr[$key] = 'null';        }      }    }    return $arr;  }    public function allfiles($path){    $allfiles = $this -> refiles($path);    if($allfiles){      $newallfiles = $this -> reall($allfiles,$path);      $allfiles =$newallfiles;    }    return $allfiles;  }    public function Dloop($arr,$path,$space=0,$spaces=0){    foreach($arr as $key => $val){      if(is_array($val)){        $spaces += 15;        $newpath = $path.$key."/";        $str .= '
.$space.'px;">'.$key.''.$kb.' 
'.$fn.''.$kb.' 


转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号