Last active
June 22, 2017 08:21
-
-
Save benjamin-dk/7951ad8891c4135fdf995ffd3fcc37c1 to your computer and use it in GitHub Desktop.
How to delete directory with PHP on FreeBSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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