I wonder, what's the easiest way to delete a directory with all its files in it?
I'm using rmdir(PATH . '/' . $value);
to delete a folder, however, if there are files inside of it, I simply can't delete it.
I wonder, what's the easiest way to delete a directory with all its files in it?
I'm using rmdir(PATH . '/' . $value);
to delete a folder, however, if there are files inside of it, I simply can't delete it.
What about this:
I prefer this because it still returns TRUE when it succeeds and FALSE when it fails, and it also prevents a bug where an empty path might try and delete everything from '/*' !!:
What about this?
Refrence: https://paulund.co.uk/php-delete-directory-and-files-in-directory
Short function that does the job:
I use it in a Utils class like this:
With great power comes great responsibility: When you call this function with an empty value, it will delete files starting in root (
/
). As a safeguard you can check if path is empty:Here you have one nice and simple recursion for deleting all files in source directory including that directory:
Function is based on recursion made for copying directory. You can find that function here: Copy entire contents of a directory to another using php
Something like this?