PHP:最简单的方法来删除一个文件夹(包括其内容) [英] PHP: Simplest way to delete a folder (including its contents)

查看:129
本文介绍了PHP:最简单的方法来删除一个文件夹(包括其内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果文件夹包含任何文件,则 rmdir()函数将失败。我可以通过这样的方式遍历目录中的所有文件:

  foreach(scandir($ dir)as $ item){
if($ item =='。'|| $ item =='..')continue;
unlink($ dir.DIRECTORY_SEPARATOR。$ item);
}
rmdir($ dir);

有没有办法一次删除它?


< ($ / $> $ / $> $ / $> $ / $> $ / $> $系统('/ bin / rm -rf。escapeshellarg($ dir));

可用。

The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this:

foreach (scandir($dir) as $item) {
    if ($item == '.' || $item == '..') continue;
    unlink($dir.DIRECTORY_SEPARATOR.$item);
}
rmdir($dir);

Is there any way to just delete it all at once?

解决方案

Well, there's always

system('/bin/rm -rf ' . escapeshellarg($dir));

where available.

这篇关于PHP:最简单的方法来删除一个文件夹(包括其内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆