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 Exception if the path is restricted (validated by is_path_valid()).
  • Throws Exception if the path is not a directory.
  • Throws Exception if 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/).