Re: [請益] 遞迴刪除資料夾
拿官網上面提供的 function:
<?php
$dir = "/path/to/base/dir";
recursive_delete($dir);
function recursive_delete( $dir )
{
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false ) {
if( $file != "." && $file != ".." )
{
if( is_dir( $dir . $file ) )
{
echo "Entering Directory: $dir$file<br/>";
recursive_delete( $dir . $file . "/" );
echo "Removing Directory: $dir$file<br/><br/>";
rmdir( $dir . $file );
}
else
{
echo "Deleting file: $dir$file<br/>";
unlink( $dir . $file );
}
}
}
closedir($dh);
}
}
}
?>
ref: http://tw.php.net/manual/fr/function.opendir.php#59599
跟你寫的差不多 ~ 你試試看
--
AppleBoy Blog: http://blog.wu-boy.com
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.115.150.138
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章