欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP删除文件夹内及其文件

程序员文章站 2022-05-12 11:11:29
...

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.

?>