Dbmier LED Artcraft Tracing Light Pad Light Box Light Board Light Table- A4

PHP Tech Blog

Dbmier LED Artcraft Tracing Light Pad Light Box Light Board Light Table- A4

留言簿(5)

Links

My Favorites

推荐技术文章

阅读排行榜

评论排行榜

PHP得到根目录和删除文件,删除目录

<?php
$file = "test.txt";
if (!unlink($file))
  {
  echo ("Error deleting $file");
  }
else
  {
  echo ("Deleted $file");
  }
?>



php可以获得站点的根目录
function GetRootPath()
{
        $sRealPath = realpath( './' ) ;

        $sSelfPath = $_SERVER['PHP_SELF'] ;
        $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;

        return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
}


通过$_SERVER["DOCUMENT_ROOT"]变量取虚拟目录

  1. function removeDir($dirName)
  2. {
  3.     $result = false;
  4.     if(! is_dir($dirName))
  5.     {
  6.         trigger_error("目录名称错误", E_USER_ERROR);
  7.     }
  8.     $handle = opendir($dirName);
  9.     while(($file = readdir($handle)) !== false)
  10.     {
  11.         if($file != '.' && $file != '..')
  12.         {
  13.             $dir = $dirName . DIRECTORY_SEPARATOR . $file;
  14.             is_dir($dir) ? removeDir($dir) : unlink($dir);
  15.         }
  16.     }
  17.     closedir($handle);
  18.     $result = rmdir($dirName) ? true : false;
  19.     return $result;
  20. }


<?php
 
function remove_directory($dir) {
  if ($handle = opendir("$dir")) {
   while (false !== ($item = readdir($handle))) {
     if ($item != "." && $item != "..") {
       if (is_dir("$dir/$item")) {
         remove_directory("$dir/$item");
       } else {
         unlink("$dir/$item");
         echo " removing $dir/$item<br>\n";
       }
     }
   }
   closedir($handle);
   rmdir($dir);
   echo "removing $dir<br>\n";
  }
}
 
 
function removeDir($dirName)
{
    if(! is_dir($dirName))
    {
        return false;
    }
    $handle = @opendir($dirName);
    while(($file = @readdir($handle)) !== false)
    {
        if($file != '.' && $file != '..')
        {
            $dir = $dirName . '/' . $file;
            is_dir($dir) ? removeDir($dir) : @unlink($dir);
        }
    }
    closedir($handle);
   
    return rmdir($dirName) ;
}
?>

posted on 2009-05-13 11:29 haix 阅读(1283) 评论(0)  编辑 收藏 引用 网摘 所属分类: PHP


只有注册用户登录后才能发表评论。
网站导航:
Dbmier LED Artcraft Tracing Light Pad Light Box Light Board Light Table- A4