php最简单的删除目录与文件实现方法,
本文实例讲述了php最简单的删除目录与文件实现方法。分享给大家供大家参考。
具体实现代码如下:
复制代码 代码如下:
//删除目录下所有空目录
array_map('rmdir', glob('*', GLOB_ONLYDIR));
//删除目录所有文件
array_map('unlink', array_filter(glob('*'), 'is_file'));
?>
原理分析:array_map('rmdir', glob('*', GLOB_ONLYDIR));
删除简单是使用了array_map函数,它的作用是返回用户自定义函数作用后的数组,回调函数接受的参数数目应该和传递给 array_map() 函数的数组数目一致,而glob是遍历目录,然后把返回数组给了rmdir进行目录删除,然后:
复制代码 代码如下:
array_map('unlink', array_filter(glob('*'), 'is_file'));
原理差不多了,就是遍历目录之后我们再删除指定目录中的文件即可.
希望本文所述对大家的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software