Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php deletes the current folder

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to delete the current folder by php". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to delete the current folder by php.

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How does php delete the current folder?

PHP deletes all files in the current directory and its directory

Use PHP to traverse all directories and files under a directory, and delete all subdirectories and files under the directory. This code is realized by recursion.

Functions used:

Scandir ($path) iterates through all the files in a directory and returns an array.

Unlink ($filename) deletes the file.

Rmdir ($path) deletes only empty folders.

PHP Code:

/ * delete all directories and files under the current directory and its directory * @ param string $path directories to be deleted * @ note $path path without slashes / (for example: correct [$path='./linuxidc/image'] Error [$path='./linuxidc/image/']) * / function deleteDir ($path) {if (is_dir ($path)) {/ / scan all directories and files in a directory and return the array $dirs = scandir ($path) Foreach ($dirs as $dir) {/ / exclude the current directory (.) And the next level directory (..) If ($dir! ='.'& & $dir! ='..') {/ / Recursive subdirectories if it is a directory, continue with $sonDir = $path.'/'.$dir; if (is_dir ($sonDir)) {/ / Recursively delete deleteDir ($sonDir) / / delete the empty directory @ rmdir ($sonDir) after deleting the subdirectories and files in the directory;} else {/ / if the files are deleted directly @ unlink ($sonDir);} @ rmdir ($path);}}

At this point, I believe you have a deeper understanding of "php how to delete the current folder". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report