php 删除无限级目录与文件代码共享

yipeiwu_com6年前PHP代码库
<?
//删除目录
class del_path
{
function wm_chief_delpath($del_path)
{
if(!file_exists($del_path))//目标目录不存在则建立
{echo"目录不存在";return false;}
$hand=opendir($del_path);
$i=0;
while($file=readdir($hand))
{$i ;
if($i==1||$i==2)
{continue;}
if(!(strchr($file,".")))
{
$del_s_path=$del_path."/".$file;
$this->wm_chief_delpath($del_s_path);
}
else
{
$del_file=$del_path."/".$file;
$this->wm_chief_file($del_file);
}
}
closedir($hand);
$this->wm_chief_path($del_path);
return true;
}
//删除文件
function wm_chief_file($del_file)
{
unlink($del_file);
}
//删除目录
function wm_chief_path($del_path)
{
rmdir($del_path);
}
}
$DelPath="DelPath";//要删除的目录
$wm_chief=new del_path();
$wm_chief_ok=$wm_chief->wm_chief_delpath($DelPath);
if($wm_chief_ok)
{
echo"删除完毕";
}
?>

相关文章

php实现等比例压缩图片

本文实例为大家分享了php实现等比例压缩图片的具体代码,供大家参考,具体内容如下 /** * desription 压缩图片 * @param sting $imgsrc...

PHP函数实现分页含文本分页和数字分页

PHP函数实现分页含文本分页和数字分页

最近,在项目中要用到分页。分页功能是经常使用的一个功能,所以,对其以函数形式进行了封装。 // 分页分装 /** * $pageType 分页类型 1是数字分页 2是文本分页 * 可...

php header 详细使用说明与使用心得第1/2页

不管页面有多少header,它会执行最后一个,不过是有条件的,例如: header('Location://www.jb51.net'); header('Location:http:/...

PHP简单实现模拟登陆功能示例

本文实例讲述了PHP简单实现模拟登陆功能。分享给大家供大家参考,具体如下: 在不考虑验证码的情况一下,php实现模拟登陆,网上给的办法一般是采用curl来模拟实现,但是curl实现的是服...

PHP 读取和修改大文件的某行内容的代码

复制代码 代码如下: $fp = fopen('d:/file.txt', 'r+'); if ($fp) { $i = 1; while (!feof($fp)) { //修改第二行数...