当前位置:Gxlcms > PHP教程 > PHP删除文件夹内及其文件

PHP删除文件夹内及其文件

时间:2021-07-01 10:21:17 帮助过:6人阅读

function Delete($path){

if (is_dir($path) === true)

{

$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $file)

{

Delete(realpath($path) . '/' . $file);

}

return rmdir($path);

}

else if (is_file($path) === true)

{

return unlink($path);

}

return false;

}

语法:

$path = "images/";

Delete($path); // This will delete images folder along with its contents.

?>

人气教程排行