该函数功能:
1、删除目录及目录下所有的文件
2、删除目录下的所有文件但目录结构保留
3、删除指定文件
贴代码/**<br>
+-----------------------------------------------------------------------------------------<br>
* 删除目录及目录下所有文件或删除指定文件<br>
+-----------------------------------------------------------------------------------------<br>
* @param str $path 待删除目录路径<br>
* @param int $delDir 是否删除目录,1或true删除目录,0或false则只删除文件保留目录(包含子目录)<br>
+-----------------------------------------------------------------------------------------<br>
* @return bool 返回删除状态<br>
+-----------------------------------------------------------------------------------------<br>
*/<br>
function delDirAndFile($path, $delDir = FALSE) {<br>
if (is_array($path)) {<br>
foreach ($path as $subPath)<br>
delDirAndFile($subPath, $delDir);<br>
}<br>
if (is_dir($path)) {<br>
$handle = opendir($path);<br>
if ($handle) {<br>
while (false !== ( $item = readdir($handle) )) {<br>
if ($item != "." && $item != "..")<br>
is_dir("$path/$item") ? delDirAndFile("$path/$item", $delDir) : unlink("$path/$item");<br>
}<br>
closedir($handle);<br>
if ($delDir)<br>
return rmdir($path);<br>
}<br>
} else {<br>
if (file_exists($path)) {<br>
return unlink($path);<br>
} else {<br>
return FALSE;<br>
}<br>
}<br>
clearstatcache();<br>
}
这个函数和unlink有什么不一样?如果知道要删除的是一个文件可以直接使用unlink函数,如果不知道要删除的是一个文件还是文件件就可以使用上面的函数
本文在我的blog里对应的地址是:http://blog.51edm.org/post/102
AD:真正免费,域名+虚机+企业邮箱=0元

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

SublimeText3 Chinese version
Chinese version, very easy to use

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),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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