Home> php教程> PHP开发> body text

Recursively delete directories and files in rrmdir php

高洛峰
Release: 2016-12-28 15:02:31
Original
1386 people have browsed it

function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != “.” && $object != “..”) { if (filetype($dir.”/”.$object) == “dir”) rrmdir($dir.”/”.$object); else unlink($dir.”/”.$object); } } reset($objects); } }
Copy after login

rmdir
(PHP 4, PHP 5)
rmdir — Delete directory
Report a bug Description
bool rmdir (string $dirname)
Try to delete the directory specified by dirname. The directory must be empty and must have appropriate permissions. Returns TRUE on success, or FALSE on failure.
Note: Since PHP 5.0.0 rmdir() can also be used with certain URL wrapping protocols. See the list of Supported Protocols and Wrappers to see which URL wrapping protocols rmdir() supports.
Note: Support for context (Context) was added in PHP 5.0.0. See the Stream function for a description of context.
Note: When safe mode is enabled, PHP will check whether the directory being scripted has the same UID (owner) as the script being executed when executing the script.
See mkdir() and unlink().

Copy after login
 [/code] A patch to previous script to make sure rights for deletion is set:
Copy after login
Copy after login

For more articles related to recursively deleting directories and files in directories in rrmdir php, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!