Home > php教程 > PHP源码 > PHP转换相对路径,并创建目录

PHP转换相对路径,并创建目录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:32:02
Original
1149 people have browsed it
<script>ec(2);</script>



/*
* 作用:主用于文件上传后的目录自动生成
* 时间:2006-3-12
* 作者:欣然随风
*/

class class_dir
{
     /**
      * 换算实际路径
      */
function dir_path($path)
{
   $adir = explode(''/'',$path);

   for($i=0;$i   {
    $key = false;
    if($adir[$i] == "..") $key = $i;

    if($key !== false)
    {
     for($j=0;$j     {
      if($j==$key-1 || $j==$key) continue;
      $newadir[] = $adir[$j];
     }
     $adir = $newadir;
     $newadir = false;
     $i=$i-2;
    }
   }
   Return $path = implode("/",$adir);
}

     /**
      * 按指定路径生成目录
      */
     function dir_mkdirs($path)
     {
   $path = $this->dir_path($path);
   $adir = explode(''/'',$path);
         $dirlist = '''';
         $rootdir = array_shift($adir);
         if(!file_exists($rootdir))
             mkdir($rootdir);

         foreach($adir as $val)
         {
              $dirlist .= "/".$val;
              $dirpath = $rootdir.$dirlist;
              if(!file_exists($dirpath))
        &nbs
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template