From 7b7d0cc9548fec9a127afb701b3aa1a94aa282c5 Mon Sep 17 00:00:00 2001 From: steinm Date: Thu, 25 Nov 2010 21:11:03 +0000 Subject: [PATCH] - put all functions into a class LetoDMS_File --- inc/inc.FileUtils.php | 324 ++++++++++++++++++++---------------------- 1 file changed, 155 insertions(+), 169 deletions(-) diff --git a/inc/inc.FileUtils.php b/inc/inc.FileUtils.php index 76469ce95..8404c18ee 100644 --- a/inc/inc.FileUtils.php +++ b/inc/inc.FileUtils.php @@ -1,175 +1,161 @@ -_contentDir)); - - $mkfolder = $settings->_contentDir; - - $path = preg_split( "/[\\\\\/]/" , $path ); - - for( $i=0 ; isset( $path[$i] ) ; $i++ ) - { - if(!strlen(trim($path[$i])))continue; - $mkfolder .= $path[$i]; - - if( !is_dir( $mkfolder ) ){ - $res= @mkdir( "$mkfolder" , 0777); - if (!$res) return false; - } - $mkfolder .= DIRECTORY_SEPARATOR; +class LetoDMS_File { + function renameFile($old, $new) { + return @rename($old, $new); } - - return true; - -} - -function removeDir($path) -{ - $handle = @opendir($path); - while ($entry = @readdir($handle) ) - { - if ($entry == ".." || $entry == ".") - continue; - else if (is_dir($path . $entry)) - { - if (!removeDir($path . $entry . "/")) - return false; - } - else - { - if (!@unlink($path . $entry)) - return false; - } - } - @closedir($handle); - return @rmdir($path); -} - -function copyDir($sourcePath, $targetPath) -{ - if (mkdir($targetPath, 0777)) - { - $handle = @opendir($sourcePath); - while ($entry = @readdir($handle) ) - { - if ($entry == ".." || $entry == ".") - continue; - else if (is_dir($sourcePath . $entry)) - { - if (!copyDir($sourcePath . $entry . "/", $targetPath . $entry . "/")) - return false; - } - else - { - if (!@copy($sourcePath . $entry, $targetPath . $entry)) - return false; - } - } - @closedir($handle); - } - else - return false; - - return true; -} - -function moveDir($sourcePath, $targetPath) -{ - if (!copyDir($sourcePath, $targetPath)) - return false; - return removeDir($sourcePath); -} -// code by Kioob (php.net manual) -function gzcompressfile($source,$level=false) -{ - $dest=$source.'.gz'; - $mode='wb'.$level; - $error=false; - if($fp_out=@gzopen($dest,$mode)){ - if($fp_in=@fopen($source,'rb')){ - while(!feof($fp_in)) - @gzwrite($fp_out,fread($fp_in,1024*512)); - @fclose($fp_in); + function removeFile($file) { + return @unlink($file); + } + + function copyFile($source, $target) { + return @copy($source, $target); + } + + function moveFile($source, $target) { + if (!@copyFile($source, $target)) + return false; + return @removeFile($source); + } + + function renameDir($old, $new) { + return @rename($old, $new); + } + + function makeDir($path) { + /* + if (strncmp($path, DIRECTORY_SEPARATOR, 1) == 0) { + $mkfolder = DIRECTORY_SEPARATOR; + } + else { + $mkfolder = ""; + } + $path = preg_split( "/[\\\\\/]/" , $path ); + for( $i=0 ; isset( $path[$i] ) ; $i++ ) + { + if(!strlen(trim($path[$i])))continue; + $mkfolder .= $path[$i]; + + if( !is_dir( $mkfolder ) ){ + $res=@mkdir( "$mkfolder" , 0777); + if (!$res) return false; + } + $mkfolder .= DIRECTORY_SEPARATOR; + } + + return true;*/ + + // patch from alekseynfor safe_mod or open_basedir + + global $settings; + $path = substr_replace ($path, "/", 0, strlen($settings->_contentDir)); + + $mkfolder = $settings->_contentDir; + + $path = preg_split( "/[\\\\\/]/" , $path ); + + for( $i=0 ; isset( $path[$i] ) ; $i++ ) + { + if(!strlen(trim($path[$i])))continue; + $mkfolder .= $path[$i]; + + if( !is_dir( $mkfolder ) ){ + $res= @mkdir( "$mkfolder" , 0777); + if (!$res) return false; + } + $mkfolder .= DIRECTORY_SEPARATOR; + } + + return true; + + } + + function removeDir($path) { + $handle = @opendir($path); + while ($entry = @readdir($handle) ) + { + if ($entry == ".." || $entry == ".") + continue; + else if (is_dir($path . $entry)) + { + if (!removeDir($path . $entry . "/")) + return false; + } + else + { + if (!@unlink($path . $entry)) + return false; + } + } + @closedir($handle); + return @rmdir($path); + } + + function copyDir($sourcePath, $targetPath) { + if (mkdir($targetPath, 0777)) { + $handle = @opendir($sourcePath); + while ($entry = @readdir($handle) ) { + if ($entry == ".." || $entry == ".") + continue; + else if (is_dir($sourcePath . $entry)) { + if (!copyDir($sourcePath . $entry . "/", $targetPath . $entry . "/")) + return false; + } else { + if (!@copy($sourcePath . $entry, $targetPath . $entry)) + return false; + } + } + @closedir($handle); + } + else + return false; + + return true; + } + + function moveDir($sourcePath, $targetPath) { + if (!copyDir($sourcePath, $targetPath)) + return false; + return removeDir($sourcePath); + } + + // code by Kioob (php.net manual) + function gzcompressfile($source,$level=false) { + $dest=$source.'.gz'; + $mode='wb'.$level; + $error=false; + if($fp_out=@gzopen($dest,$mode)) { + if($fp_in=@fopen($source,'rb')) { + while(!feof($fp_in)) + @gzwrite($fp_out,fread($fp_in,1024*512)); + @fclose($fp_in); + } + else $error=true; + @gzclose($fp_out); } else $error=true; - @gzclose($fp_out); + + if($error) return false; + else return $dest; } - else $error=true; - - if($error) return false; - else return $dest; -} - -?> +} +?>