- added method checksum()

This commit is contained in:
steinm 2013-02-08 15:05:24 +00:00
parent a1f71b7373
commit f32de01d60

View File

@ -25,39 +25,39 @@
* @version Release: @package_version@ * @version Release: @package_version@
*/ */
class LetoDMS_Core_File { class LetoDMS_Core_File {
function renameFile($old, $new) { function renameFile($old, $new) { /* {{{ */
return @rename($old, $new); return @rename($old, $new);
} } /* }}} */
function removeFile($file) { function removeFile($file) { /* {{{ */
return @unlink($file); return @unlink($file);
} } /* }}} */
function copyFile($source, $target) { function copyFile($source, $target) { /* {{{ */
return @copy($source, $target); return @copy($source, $target);
} } /* }}} */
function moveFile($source, $target) { function moveFile($source, $target) { /* {{{ */
if (!@copyFile($source, $target)) if (!@copyFile($source, $target))
return false; return false;
return @removeFile($source); return @removeFile($source);
} } /* }}} */
function fileSize($file) { function fileSize($file) { /* {{{ */
if(!$a = fopen($file, 'r')) if(!$a = fopen($file, 'r'))
return false; return false;
fseek($a, 0, SEEK_END); fseek($a, 0, SEEK_END);
$filesize = ftell($a); $filesize = ftell($a);
fclose($a); fclose($a);
return $filesize; return $filesize;
} } /* }}} */
function format_filesize($size, $sizes = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')) { function format_filesize($size, $sizes = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')) { /* {{{ */
if ($size == 0) return('0 Bytes'); if ($size == 0) return('0 Bytes');
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $sizes[$i]); return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $sizes[$i]);
} } /* }}} */
function parse_filesize($str) { function parse_filesize($str) { /* {{{ */
preg_replace('/\s\s+/', ' ', $str); preg_replace('/\s\s+/', ' ', $str);
if(strtoupper(substr($str, -1)) == 'B') { if(strtoupper(substr($str, -1)) == 'B') {
$value = (int) substr($str, 0, -2); $value = (int) substr($str, 0, -2);
@ -81,13 +81,17 @@ class LetoDMS_Core_File {
break; break;
} }
return false; return false;
} } /* }}} */
function renameDir($old, $new) { function checksum($file) { /* {{{ */
return md5_file($file);
} /* }}} */
function renameDir($old, $new) { /* {{{ */
return @rename($old, $new); return @rename($old, $new);
} } /* }}} */
function makeDir($path) { function makeDir($path) { /* {{{ */
if( !is_dir( $path ) ){ if( !is_dir( $path ) ){
$res=@mkdir( $path , 0777, true); $res=@mkdir( $path , 0777, true);
@ -140,9 +144,9 @@ class LetoDMS_Core_File {
return true; return true;
*/ */
} } /* }}} */
function removeDir($path) { function removeDir($path) { /* {{{ */
$handle = @opendir($path); $handle = @opendir($path);
while ($entry = @readdir($handle) ) while ($entry = @readdir($handle) )
{ {
@ -161,9 +165,9 @@ class LetoDMS_Core_File {
} }
@closedir($handle); @closedir($handle);
return @rmdir($path); return @rmdir($path);
} } /* }}} */
function copyDir($sourcePath, $targetPath) { function copyDir($sourcePath, $targetPath) { /* {{{ */
if (mkdir($targetPath, 0777)) { if (mkdir($targetPath, 0777)) {
$handle = @opendir($sourcePath); $handle = @opendir($sourcePath);
while ($entry = @readdir($handle) ) { while ($entry = @readdir($handle) ) {
@ -183,16 +187,16 @@ class LetoDMS_Core_File {
return false; return false;
return true; return true;
} } /* }}} */
function moveDir($sourcePath, $targetPath) { function moveDir($sourcePath, $targetPath) { /* {{{ */
if (!copyDir($sourcePath, $targetPath)) if (!copyDir($sourcePath, $targetPath))
return false; return false;
return removeDir($sourcePath); return removeDir($sourcePath);
} } /* }}} */
// code by Kioob (php.net manual) // code by Kioob (php.net manual)
function gzcompressfile($source,$level=false) { function gzcompressfile($source,$level=false) { /* {{{ */
$dest=$source.'.gz'; $dest=$source.'.gz';
$mode='wb'.$level; $mode='wb'.$level;
$error=false; $error=false;
@ -209,6 +213,6 @@ class LetoDMS_Core_File {
if($error) return false; if($error) return false;
else return $dest; else return $dest;
} } /* }}} */
} }
?> ?>