这是一款删除文件夹的php函数,本函数用的是递归删除,他可以删除指定目录的所有文件夹与文件,可以删除不是空目录的文件夹,方便的很,下面来看看函数实例方法。
代码如下 | 复制代码 |
/*—————————————————— */ //– 递归删除文件及目录 //– 例: del_dir ('../www.1111cn.net/');注意:返回的/是必须的 //– $type 强制删除目录, true 是 ,false 否 /*—————————————————— */ function del_dir ($dir,$type=true) { $n=0; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //.svn 忽略 svn 版本控制信息 if ( $file == '.' or $file =='..' or $file == '.svn') { continue; } if (is_file ($dir.$file)) { unlink($dir.$file); $n++; } if (is_dir ($dir.$file)) { del_dir ($dir.$file.'/'); if ($type) { $n++; rmdir($dir.$file.'/'); } } } } closedir($dh); } return $n; } |
很容易看懂吧。原理很简单,首先是查询目录所有文件或目录,如果是文件就删除了,如果是目录看看是不是空目录,如果是的删除,否则再调用本函数一次类推,就实例了删除不是空目录的功能了。

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
