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) 只删除空文件夹
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!