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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:32:021144Durchsuche
<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
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn