Home > Backend Development > PHP Tutorial > How to delete all files and folders under a path in php

How to delete all files and folders under a path in php

小云云
Release: 2023-03-20 07:12:02
Original
3617 people have browsed it

This article mainly shares with you the code of how to delete all files and folders in a path in PHP. PHP traverses all files and folders in a folder and deletes all files in all folders and subfolders. By The recursive method achieves the effect of clearing a directory, and the code is simple and practical.

is also suitable for clearing the cache in thinkphp. In thinkphp, you can write the following code into the ./Application/Admin/Common/function.php file, and then call this function in the controller to perform the cleaning operation. .

Functions used:

 scandir($path)    遍历一个文件夹所有文件并返回数组。
    unlink($filename)    删除文件。
    rmdir($path)    只删除空文件夹
Copy after login
rrree

Related recommendations:

PHP’s unlink and rmdir methods to delete a directory and all files in the directory

php batch conversion method of encoding all files in a folder

PHP uses one line of code to delete all files in a directory Detailed explanation

The above is the detailed content of How to delete all files and folders under a path in php. For more information, please follow other related articles on 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template