Filesystem.class.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class Filesystem extends Auth {
  3. protected function __construct() {
  4. parent::__construct();
  5. }
  6. /* deleteDir - loesche ein Verzeichnis rekursiv
  7. * Rueckgabewerte:
  8. * 0 - alles ok
  9. * -1 - kein Verzeichnis
  10. * -2 - Fehler beim Loeschen
  11. * -3 - Ein Eintrag eines Verzeichnisses war keine Datei und kein Verzeichnis und
  12. * kein Link
  13. */
  14. protected function deleteDir ($path) {
  15. if (!is_dir ($path))return -1;
  16. $dir = @opendir ($path);
  17. if (!$dir)return -2;
  18. while (($entry = @readdir($dir)) !== false) {
  19. if ($entry == '.' || $entry == '..') continue;
  20. if (is_dir ($path.'/'.$entry)) {
  21. $res = $this->deleteDir($path.'/'.$entry);
  22. if ($res == -1) {
  23. @closedir ($dir);
  24. return -2;
  25. } else if ($res == -2) {
  26. @closedir ($dir);
  27. return -2;
  28. } else if ($res == -3) {
  29. @closedir ($dir);
  30. return -3;
  31. } else if ($res != 0) {
  32. @closedir ($dir);
  33. return -2;
  34. }
  35. } else if (is_file ($path.'/'.$entry) || is_link ($path.'/'.$entry)) {
  36. $res = @unlink ($path.'/'.$entry);
  37. if (!$res) {
  38. @closedir ($dir);
  39. return -2;
  40. }
  41. } else {
  42. @closedir ($dir);
  43. return -3;
  44. }
  45. }
  46. @closedir ($dir);
  47. $res = @rmdir ($path);
  48. if (!$res) return -2;
  49. return 0;
  50. }
  51. static public function standardDirFormat() {
  52. $args = func_get_args();
  53. $i=0;
  54. $path="";
  55. foreach($args as $piece) {
  56. if($i>0 && (substr($piece,0,2) == "./" || substr($piece,0,2) == ".\\")) {
  57. $path .= substr($piece,2);
  58. }else if($i==0) {
  59. $path .= $piece;
  60. }
  61. }
  62. if(substr($path, -1) != "/" && substr($path, -1) != "\\") $path = $path . DIRECTORY_SEPARATOR;
  63. else $path = $path;
  64. return $path;
  65. }
  66. }
  67. ?>