Created
July 19, 2013 07:52
-
-
Save Leask/6037457 to your computer and use it in GitHub Desktop.
A lightweight file system lib in php
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 | |
# 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