Skip to content

Instantly share code, notes, and snippets.

@benjamin-dk
Last active June 22, 2017 08:21
Show Gist options
  • Save benjamin-dk/7951ad8891c4135fdf995ffd3fcc37c1 to your computer and use it in GitHub Desktop.
Save benjamin-dk/7951ad8891c4135fdf995ffd3fcc37c1 to your computer and use it in GitHub Desktop.
How to delete directory with PHP on FreeBSD
<?php
/* Its been a while since I used this so please use at your own risk */
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
self::deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
function changeOwner() {
$user_name = "username";
$path = "/path/to/dir";
//chown($path, $user_name);
chgrp($path, $user_name);
}
/*deleteDir('/path/to/dir');*/
changeOwner();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment