delete_directory()
public function delete_directory(string $directory_path): bool
Description
Recursively deletes a directory and all its contents (files and subdirectories). Includes security validation to prevent deletion of restricted paths.
Warning: This operation is irreversible. Use with extreme caution.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $directory_path | string | Absolute or relative path to the directory to delete. |
Return Value
| Type | Description |
|---|---|
| bool | true if the directory was successfully deleted. |
Example Usage
Notes
- Throws
Exceptionif the path is restricted (validated byis_path_valid()). - Throws
Exceptionif the path is not a directory. - Throws
Exceptionif the directory cannot be deleted (e.g., permissions). - Uses recursion to delete nested subdirectories.
- Security: Only allows deletion within permitted application paths (e.g.,
uploads/,cache/).