I would like to delete a file that is found in my localhost.
localhost/project/folder/file_to_delete
I\'m using codeigniter for this.
This code can also handle non-empty folders - just use it in a helper.
if (!function_exists('deleteDirectory')) {
function deleteDirectory($dir) {
if (!file_exists($dir)) return true;
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if (!deleteDirectory($dir . "/" . $item)) {
chmod($dir . "/" . $item, 0777);
if (!deleteDirectory($dir . "/" . $item)) return false;
};
}
return rmdir($dir);
}
}