首页 » PHP » 阅读文章

解说php删除文件函数unlink如何删除文件夹

2011-01-04 10:06 4911 0 发表评论
标签:

以实例来说明 php删除文件函数unlink 的应该:
首先创建一个文件,名为test.txt 。
*********************************
// 判断文件是否存在.
$myFile = “test.txt”;
$fh = fopen($myFile, ‘w’) or die(”can’t open file”);
fclose($fh);

// 删除文件.
$myFile = “test.txt”;
unlink($myFile);
*********************************

在PHP程序中如何删除文件夹呢
*********************************
首先先定义一个deldir函数
function deldir($dir) {
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!=”.” && $file!=”..”) {
$fullpath=$dir.”/”.$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)) {
return true;
} else {
return false;
}
}

接着运用这个函数就行了,如

deldir(txt); //txt表示路径文件夹
*********************************

本文地址:http://www.jwzzsw.com/archives/705.html

文章作者:思悟
版权所有 © 转载时请以链接形式注明作者和原始出处!

评论 共0条 (RSS 2.0) 发表评论

  1. 暂无评论,快抢沙发吧。

发表评论

联系我 Contact Me

回到页首