Source for file pcf_directory.phpinc
Documentation is available at pcf_directory.phpinc
* Common Directory Functions
* @project Open CSP-Management
* @author Peter Krebs (pk)<p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: pcf_directory.phpinc,v 1.11 2008/11/06 08:41:58 pitlinz Exp $
require
__OCSP_PHPINCPATH__.
"common".
_OCSP_DIRSEP_.
"pcf_file.phpinc";
* returns an array of directories like a tree
* 3: /home/user1/public_html
* this function calls itself recursive until $level==0
* or no subdirectories exists
* this function is slow with a large directory tree
* take care start point ($aDir) is set correct
* - open_basedir restrictions
* - safe_mode restrictions
* - not getting the whole dir structure as result
* @param string $aDir start directory
* @param array &$dirArr return array
* @param bool $goDown add subdirectory subdirs to array
* @param string $path path to add to the dirArray Value
* @param string $excludes do not add this directories and subdirectories
* @param int $levels max number of going into subdir
function pcf_dirArray($aDir,&$dirArr,$goDown=
TRUE,$path=
"",$excludes=
"",$levels=
10) {
// echo "pcf_dirArray: $aDir<br />";
if (empty($path)) $dirArr[]=
"/";
while ($file =
readdir($dirHandle)) {
if (($file !=
".") &&
($file !=
"..")) {
if (is_dir($aDir.
"/".
$file)) {
if (empty($excludes) ||
(!strstr($excludes,$file))) {
$dirArr[]=
$path.
"/".
$file;
pcf_dirArray($aDir.
"/".
$file,$dirArr,$goDown,$path.
"/".
$file,$excludes,($levels-
1));
* returns an array with files of a specified type in a directory
* . !D = WITHOUT DIRECTORIES (pk-04-08-18)
* Combination of types are also allowed
* FL returns files and links
* @param string $dirName (the directory)
* @param string $type (file type(s))
* @param array $blackList
* @version pk-07-02-28 handle last slash
* @version pk-07-09-04 follow links in FL an DL
* @version pk-07-10-03 hide files ending with ~
* @version pk-07-11-12 $blackList added
function pcf_getDirList($dirName,$type=
"F",$debug=
FALSE,$blackList=
array()) {
if ($debug) echoDebug(__FILE__
,"<p><b>pcf_getDirList($dirName,$type,...)</b><p>");
if (substr($dirName,-
1) !=
"/") $dirName.=
"/";
if ($debug) echo
"<p>Directory: $dirName</p>";
while ($file =
@readdir($dirHandle)) {
if ($debug) echo
"<p>File: $file</p>";
if ((!in_array($file,$blackList)) &&
($file !=
".") &&
($file !=
"..") &&
(substr($file,-
1) !=
'~'))
} else if ((strstr($type,"F") &&
strstr($type,"L")) &&
(is_link($dirName.
$file))) { // <pk-07-09-04>
} else if ((strstr($type,"D")) &&
(is_dir($dirName.
$file))){
} else if ((strstr($type,"A"))) {
* checks if a directory exists and create it if necessary
* returns 1 if the directory exists
* returns 2 if there is a symlink with the name
* returns 3 if a new Directory is created
* returns False if the directory does not exists or could not be created
* @param string $aDir the directory
* @param boolean $createDir create the dir if not exists
* @param octal $rMask fileMask of the new directory if one is created
* @version pk-07-11-13 check if the link source is a directory
function pcf_checkDir($aDir,$createDir=
False,$rMask=
0770,$debug=
False) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p>Could not create: $aDir</p><hr>\n",3); // <pk-06-02-08 />
* replaces some chars in $dirname which can cause problems
* @uses pcf_checkFileName() for each directory name
* @param bool $isPath $dirName is a Path with
* @todo this function only works with linux servers for windows you can also have a drive letter like "c:"
* @todo withpath is quick and durty coded
$dirName =
trim($dirName);
$s_ret=
((substr($dirName,0,1)==
$pathSep) ?
$pathSep :
"");
if ($a_path=
explode($pathSep,$dirName)) {
foreach($a_path as $s_dir) {
* sets $dirArr with files, symlinks and dirs for a file tree
* @param string $startDir
function pcf_getDirTree(&$dirArr,$startDir,$subDir=
"",$filter=
"",$debug=
FALSE) {
while(list
($key,$val)=
each($fileList)) {
while(list
($key,$val)=
each($subDirs)) {
getDirTree($dirArr,$startDir.
"/".
$val,$subDir.
"$val/",$filter,$debug);
* @param octal $mode create mode
$ret=
@mkdir($strPath,$mode);
* remove a directory and everything that's in it.
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<strong>pcf_rmdir(</strong>$dirname<strong>)</strong>");
if ($dirHandle =
opendir($dirname)) {
while ($file =
readdir($dirHandle)) {
if ($file ==
'.' ||
$file ==
'..') continue;
* creates a direcotry with parentdir if not exists
* @param octal $mode create mode
* @param bool $debug (pk-03-12-19)
function pcf_mkdirs($strPath, $mode=
0775, $debug=
FALSE) {
if ($debug) echo "<p><b>pcf_mkdirs($strPath, $mode, $debug)</b></p>";
$projPath=pcf_checkDirName(str_replace($_SERVER['PROJECTDIR'],"",$strPath),TRUE);
$ret=system($GLOBALS['PROJECT']['BINPATH']."mkdir ".$projPath,$ok);
if ($debug) {echo "<p>".$GLOBALS['PROJECT']['BINPATH']."mkdir ".$projPath."<hr>returned: ".$ok."<hr>lastLine: $ret";}
if (empty($strPath)) return TRUE;
if (substr($strPath,-
1) ==
"/") $strPath=
substr($strPath,0,-
1);
if (is_dir($strPath)) return TRUE;
if ((!is_dir($pStrPath)) &&
(!pcf_mkdirs($pStrPath,$mode,$debug))) return FALSE;
* checks if a file is a directory
Documentation generated on Thu, 08 Jan 2009 17:47:47 +0100 by phpDocumentor 1.4.0a2