标题:
删除文件或文件夹的程序
[打印本页]
作者:
cn2002
时间:
2005-11-6 00:15
标题:
删除文件或文件夹的程序
<style>
input,body{font-family:verdana; font-size:12px; background-color:#fcfcfc}
</style>
<?php
function CleanDir($dir)
{
$handle=opendir($dir);
while ( $file=readdir($handle) )
{
if ( ($file==".") || ($file=="..") ) continue;
if ( is_dir("$dir/$file") )
{
CleanDir("$dir/$file");
if ( rmdir("$dir/$file") ) echo "Remove dir "$dir/$file" successfully!<p>";
else echo "<FONT COLOR=RED>Fail to Remove dir "$dir/$file"!</FONT><P>";
}
else
{
if ( unlink("$dir/$file") ) echo "Del file "$dir/$file" successfully!<p>";
else echo "<FONT COLOR=RED>Fail to del file "$dir/$file"!</FONT><P>";
}
}
closedir($handle);
}
if ( !IsSet($dirname) )
{
echo "<form action=$PHP_SELF method=post name=delform><center><font color=red>Folder or File</font> to be deled: <input name=dirname style="color:red"> password: <input type=password name=pass size=6> <input type=submit></center></form>";
echo " <SCRIPT> document.delform.dirname.focus() </SCRIPT> ";
}
else
{
if ($pass!="hg") die("wrong password");
if ( is_file( $dirname ) )
{
if ( unlink($dirname) ) echo "Del file "$dirname" successfully!<p>";
else echo "<FONT COLOR=RED>Fail to del file "$dirname"!</FONT><P>";
}
else
{
CleanDir($dirname);
if ( rmdir($dirname) ) echo "Remove dir "$dirname" successfully!<p>";
else echo "<FONT COLOR=RED>Fail to Remove dir "$dirname"!</FONT><P>";
}
}
?>
复制代码
欢迎光临 星星博客 (http://bbs.huhoo.net/)
Powered by Discuz! 7.0.0