Skip to content

Instantly share code, notes, and snippets.

@Leask
Created July 19, 2013 07:52
Show Gist options
  • Save Leask/6037457 to your computer and use it in GitHub Desktop.
Save Leask/6037457 to your computer and use it in GitHub Desktop.
A lightweight file system lib in php
<?php
# A lightweight file system lib in php
# by @leaskh
class libFileSystem {
public function checkPath($path) {
return $path === '/' || $path === '~';
}
public function delFolder($path) {
if ($this->checkPath($path)) {
return false;
}
return $this->emptyFolder($path) && rmdir($path);
}
public function emptyFolder($path) {
if ($this->checkPath($path)) {
return false;
}
$ph = opendir($path);
while (($file = readdir($ph))) {
if ($file !== '.' && $file !== '..') {
if (is_dir($fullpath = "{$path}/{$file}")) {
$this->delFolder($fullpath);
} else {
unlink($fullpath);
}
}
}
closedir($ph);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment