How do I delete a directory and its entire contents (files and subdirectories) in PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Have you tried the first note in the manual page of
rmdir
?Example with glob() function. It will delete all files and folders recursively, including files that starts with dot.
Once you finish running tests , just remove # from the #unlink and #rmdir in the class .
The 100% working solution
Modified variant of @XzaR solution. It does remove empty folders, when all files are deleted from them and it throws exceptions instead of returning false on errors.
There is another thread with more examples here: A recursive remove directory function for PHP?
If you are using Yii then you can leave it to the framework: