bludit/kernel/helpers/filesystem.class.php

96 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2015-05-05 03:00:01 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2015-03-08 18:02:59 +01:00
2015-05-31 03:06:55 +02:00
class Filesystem {
2015-03-08 18:02:59 +01:00
// NEW
public static function listDirectories($path, $regex='*')
{
2015-09-15 01:07:15 +02:00
$directories = glob($path.$regex, GLOB_ONLYDIR);
if(empty($directories)) {
return array();
}
return $directories;
}
public static function listFiles($path, $regex='*', $extension)
{
$files = glob($path.$regex.'.'.$extension);
if(empty($files)) {
return array();
}
return $files;
2015-03-08 18:02:59 +01:00
}
2015-05-05 03:00:01 +02:00
public static function mkdir($pathname, $recursive=false)
{
// DEBUG: Ver permisos si son correctos
return mkdir($pathname, 0755, $recursive);
}
public static function rmdir($pathname)
{
return rmdir($pathname);
}
public static function mv($oldname, $newname)
{
return rename($oldname, $newname);
}
public static function rmfile($filename)
{
return unlink($filename);
}
// OLD
2015-03-08 18:02:59 +01:00
public static function get_images($regex)
{
return self::ls(PATH_UPLOAD, $regex, '*', false, false, false);
}
// Devuelve un arreglo con el listado de archivos
// $path con una barra al final, ej: /home/
// $file_expression : *.0.*.*.*.*.*.*.*.*
// $ext : xml
// $flag_dir : si quiero listar directorios
// $sort_asc_numeric : ordeno ascedente numerico
// $sort_desc_numeric : ordeno descendente numerico
public static function ls($path, $file_expression = NULL, $ext, $flag_dir = false, $sort_asc_numeric = false, $sort_desc_numeric = true)
{
if($flag_dir)
{
$files = glob($path . $file_expression, GLOB_ONLYDIR);
}
else
{
$files = glob($path . $file_expression . '.' . $ext);
}
if( ($files==false) || (empty($files)) )
{
$files = array();
}
foreach($files as $key=>$file)
{
$files[$key] = basename($file);
}
// Sort
if($sort_asc_numeric)
{
sort($files, SORT_NUMERIC);
}
elseif($sort_desc_numeric)
{
rsort($files, SORT_NUMERIC);
}
return $files;
}
}