util class various functions, usage as namespace More...
Public Member Functions | |
| removeTrailingPathSeparators ($path) | |
| getWebspaceDir ($mode="filesystem") | |
| get webspace directory | |
| getDataDir () | |
| get data directory (outside webspace) | |
| makeDir ($a_dir) | |
| creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information. | |
| makeDirParents ($a_dir) | |
| Create a new directory and all parent directories. | |
| delDir ($a_dir) | |
| removes a dir and all its content (subdirs and files) recursively | |
| getDir ($a_dir) | |
| get directory | |
util class various functions, usage as namespace
Definition at line 37 of file class.ilUpdateUtils.php.
| ilUpdateUtils::delDir | ( | $ | a_dir | ) |
removes a dir and all its content (subdirs and files) recursively
public
| string | dir to delete |
Definition at line 206 of file class.ilUpdateUtils.php.
{
if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
{
return;
}
$current_dir = opendir($a_dir);
$files = array();
// this extra loop has been necessary because of a strange bug
// at least on MacOS X. A looped readdir() didn't work
// correctly with larger directories
// when an unlink happened inside the loop. Getting all files
// into the memory first solved the problem.
while($entryname = readdir($current_dir))
{
$files[] = $entryname;
}
foreach($files as $file)
{
if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
{
ilUtil::delDir(${a_dir}."/".${file});
}
elseif ($file != "." and $file != "..")
{
unlink(${a_dir}."/".${file});
}
}
closedir($current_dir);
rmdir(${a_dir});
}
| ilUpdateUtils::getDataDir | ( | ) |
get data directory (outside webspace)
Definition at line 81 of file class.ilUpdateUtils.php.
Referenced by ilFileSystemStorage::init().
{
return CLIENT_DATA_DIR;
//global $ilias;
//return $ilias->ini->readVariable("server", "data_dir");
}
Here is the caller graph for this function:| ilUpdateUtils::getDir | ( | $ | a_dir | ) |
get directory
Definition at line 247 of file class.ilUpdateUtils.php.
{
$current_dir = opendir($a_dir);
$dirs = array();
$files = array();
while($entry = readdir($current_dir))
{
if(is_dir($a_dir."/".$entry))
{
$dirs[$entry] = array("type" => "dir", "entry" => $entry);
}
else
{
$size = filesize($a_dir."/".$entry);
$files[$entry] = array("type" => "file", "entry" => $entry,
"size" => $size);
}
}
ksort($dirs);
ksort($files);
return array_merge($dirs, $files);
}
| ilUpdateUtils::getWebspaceDir | ( | $ | mode = "filesystem" |
) |
get webspace directory
| string | $mode use "filesystem" for filesystem operations and "output" for output operations, e.g. images |
Definition at line 55 of file class.ilUpdateUtils.php.
References $ilias.
Referenced by ilFileSystemStorage::init().
{
global $ilias;
if ($mode == "filesystem")
{
return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
}
else
{
if (defined("ILIAS_MODULE"))
{
return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
}
else
{
return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
}
}
//return $ilias->ini->readVariable("server","webspace_dir");
}
Here is the caller graph for this function:| ilUpdateUtils::makeDir | ( | $ | a_dir | ) |
creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information.
examples: a_dir = /tmp/test/your_dir a_dir = ../test/your_dir a_dir = your_dir (--> creates your_dir in current directory)
public
| string | [path] + directory name |
Definition at line 103 of file class.ilUpdateUtils.php.
{
$a_dir = trim($a_dir);
// remove trailing slash (bugfix for php 4.2.x)
if (substr($a_dir,-1) == "/")
{
$a_dir = substr($a_dir,0,-1);
}
// check if a_dir comes with a path
if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
{
$path = ".";
}
// create directory with file permissions of parent directory
umask(0000);
return @mkdir($a_dir,fileperms($path));
}
| ilUpdateUtils::makeDirParents | ( | $ | a_dir | ) |
Create a new directory and all parent directories.
Creates a new directory and inherits all filesystem permissions of the parent directory If the parent directories doesn't exist, they will be created recursively. The directory name NEEDS TO BE an absolute path, because it seems that relative paths are not working with PHP's file_exists function.
| string | $a_dir The directory name to be created public |
Definition at line 137 of file class.ilUpdateUtils.php.
Referenced by ilFileSystemStorage::create().
{
$dirs = array($a_dir);
$a_dir = dirname($a_dir);
$last_dirname = '';
while($last_dirname != $a_dir)
{
array_unshift($dirs, $a_dir);
$last_dirname = $a_dir;
$a_dir = dirname($a_dir);
}
// find the first existing dir
$reverse_paths = array_reverse($dirs, TRUE);
$found_index = -1;
foreach ($reverse_paths as $key => $value)
{
if ($found_index == -1)
{
if (is_dir($value))
{
$found_index = $key;
}
}
}
umask(0000);
foreach ($dirs as $dirindex => $dir)
{
// starting with the longest existing path
if ($dirindex >= $found_index)
{
if (! file_exists($dir))
{
if (strcmp(substr($dir,strlen($dir)-1,1),"/") == 0)
{
// on some systems there is an error when there is a slash
// at the end of a directory in mkdir, see Mantis #2554
$dir = substr($dir,0,strlen($dir)-1);
}
if (! mkdir($dir, $umask))
{
error_log("Can't make directory: $dir");
return false;
}
}
elseif (! is_dir($dir))
{
error_log("$dir is not a directory");
return false;
}
else
{
// get umask of the last existing parent directory
$umask = fileperms($dir);
}
}
}
return true;
}
Here is the caller graph for this function:| ilUpdateUtils::removeTrailingPathSeparators | ( | $ | path | ) |
Definition at line 40 of file class.ilUpdateUtils.php.
Referenced by ilFileSystemStorage::create(), ilFSStorageEvent::createDirectory(), and ilFileSystemStorage::init().
{
$path = preg_replace("/[\/\\\]+$/", "", $path);
return $path;
}
Here is the caller graph for this function:
1.7.1