Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/folder.php
Строк: 52
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VFolder
{
    public static function 
create($path$mode=0755)
    {
        
$path self::safe($path);
        if (
self::exists($path)) {
            return 
TRUE;
        }
        
        
$origmask = @umask(0);
        if (
mkdir($path$modeTRUE)) {
              @
umask($origmask);
              return 
TRUE;
        }
    
        @
umask($origmask);
        
        return 
FALSE;
    }
    
    public static function 
files($path$fullpath=TRUE$recursive=FALSE$ext=''$exclude=array())
    {
        
$path self::safe($path);
        if (!
is_dir($path)) {
              return 
FALSE;
        }

        
$files  = array();
        
$handle opendir($path);
        while ((
$file readdir($handle)) !== FALSE) {
              if ((
$file != '.') && ($file != '..')) {
                if (
$exclude) {
                      if (
in_array($file$exclude)) {
                        continue;
                      }
                }
                
                if (
is_dir($path.'/'.$file)) {
                    if (
$recursive !== FALSE) {
                        
$arr    self::files($path.'/'.$file$fullpath$recursive$ext$exclude);
                        
$files     array_merge($files$arr);
                    }
                    
                    continue;
                }
                
                if (
is_array($ext)) {
                    if (!
in_array(VFile::ext($file), $ext)) {
                        continue;
                    }
                } else {
                    if (
$ext != '') {
                          if (
VFile::ext($file) != $ext) {
                            continue;
                          }
                    }
                }
        
                if (
$fullpath) {
                      
$files[] = $path.'/'.$file;
                } else {
                      
$files[] = $file;
                }
              }
        }
    
        return 
$files;
    }

    public static function 
folders($path$fullpath=TRUE$recursive=FALSE$exclude=array())
    {
        
$path self::safe($path);
        if (!
is_dir($path)) {
              return 
FALSE;
        }

        
$folders      = array();
        
$handle     opendir($path);
        while ((
$folder readdir($handle)) !== FALSE) {
              if ((
$folder != '.') && ($folder != '..')) {
                if (
$exclude) {
                      if (
in_array($folder$exclude)) {
                        continue;
                      }
                }
                
                if (
is_dir($path.'/'.$folder)) {
                    if (
$recursive !== FALSE) {
                        
$arr        self::folders($path.'/'.$folder$fullpath$recursive$exclude);
                        
$folders     array_merge($folders$arr);
                    }
                    
                    if (
$fullpath) {
                          
$folders[] = $path.'/'.$folder;
                    } else {
                          
$folders[] = $folder;
                    }
                }                
              }
        }
    
        return 
$folders;
    }
    
    public static function 
delete($path$recursive=TRUE)
    {
        
$path self::safe($path);
        if (!
file_exists($path)) {
              return 
TRUE;
        }
    
        if (!
is_dir($path) OR is_link($path)) {
              return 
unlink($path);
        }
    
        foreach (
scandir($path) as $item) {
              if (
$item == '.' OR $item == '..') {
                continue;
              }
        
              if (!
self::delete($path.'/'.$item)) {
                @
chmod($path.'/'.$item0777);
                if (!
self::delete($path.'/'.$item)) {
                      return 
FALSE;
                }
              }
        }
    
        return 
rmdir($path);
    }
    
    public static function 
exists($path)
    {
        return (
is_dir(self::safe($path))) ? TRUE FALSE;
    }
    
    public static function 
safe($path)
    {
        
$regex = array('#[^A-Za-z0-9:_-.'.DIRECTORY_SEPARATOR.' ]#');
        return 
preg_replace($regex''$path);
    }
}
?>
Онлайн: 0
Реклама