/dede/file_class.php
https://github.com/musicpop/cms · PHP · 247 lines · 191 code · 14 blank · 42 comment · 32 complexity · ebd17d5bf7d6e1c96bf7cc8194b68a59 MD5 · raw file
- <?php if(!defined('DEDEINC')) exit('dedecms');
- /**
- * Îļþ¹ÜÀíÂß¼Àà
- *
- * @version $Id: file_class.php 1 19:09 2010Äê7ÔÂ12ÈÕZ tianya $
- * @package DedeCMS.Administrator
- * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
- * @license http://help.dedecms.com/usersguide/license.html
- * @link http://www.dedecms.com
- */
- class FileManagement
- {
- var $baseDir="";
- var $activeDir="";
- //ÊÇ·ñÔÊÐíÎļþ¹ÜÀíÆ÷ɾ³ýĿ¼£»
- //ĬÈÏΪ²»ÔÊÐí 0 ,Èç¹ûÏ£Íû¿ÉÄܹÜÀíÕû¸öĿ¼,Çë°ÑÖµÉèΪ 1 £»
- var $allowDeleteDir=0;
- //³õʼ»¯ÏµÍ³
- function Init()
- {
- global $cfg_basedir, $activepath;
- $this->baseDir = $cfg_basedir;
- $this->activeDir = $activepath;
- }
- //¸ü¸ÄÎļþÃû
- function RenameFile($oldname,$newname)
- {
- $oldname = $this->baseDir.$this->activeDir."/".$oldname;
- $newname = $this->baseDir.$this->activeDir."/".$newname;
- if(($newname!=$oldname) && is_writable($oldname))
- {
- rename($oldname,$newname);
- }
- ShowMsg("³É¹¦¸ü¸ÄÒ»¸öÎļþÃû£¡","file_manage_main.php?activepath=".$this->activeDir);
- return 0;
- }
- //´´½¨ÐÂĿ¼
- function NewDir($dirname)
- {
- $newdir = $dirname;
- $dirname = $this->baseDir.$this->activeDir."/".$dirname;
- if(is_writable($this->baseDir.$this->activeDir))
- {
- MkdirAll($dirname,$GLOBALS['cfg_dir_purview']);
- CloseFtp();
- ShowMsg("³É¹¦´´½¨Ò»¸öÐÂĿ¼£¡","file_manage_main.php?activepath=".$this->activeDir."/".$newdir);
- return 1;
- }
- else
- {
- ShowMsg("´´½¨ÐÂĿ¼ʧ°Ü£¬ÒòΪÕâ¸öλÖò»ÔÊÐíдÈ룡","file_manage_main.php?activepath=".$this->activeDir);
- return 0;
- }
- }
- /**
- * Òƶ¯Îļþ
- *
- * @access public
- * @param string $mfile Îļþ
- * @param string $mpath ·¾¶
- * @return string
- */
- function MoveFile($mfile, $mpath)
- {
- if($mpath!="" && !preg_match("#\.\.#", $mpath))
- {
- $oldfile = $this->baseDir.$this->activeDir."/$mfile";
- $mpath = str_replace("\\","/",$mpath);
- $mpath = preg_replace("#\/{1,}#", "/", $mpath);
- if(!preg_match("#^/#", $mpath))
- {
- $mpath = $this->activeDir."/".$mpath;
- }
- $truepath = $this->baseDir.$mpath;
- if(is_readable($oldfile) && is_readable($truepath) && is_writable($truepath))
- {
- if(is_dir($truepath))
- {
- copy($oldfile, $truepath."/$mfile");
- }
- else
- {
- MkdirAll($truepath, $GLOBALS['cfg_dir_purview']);
- CloseFtp();
- copy($oldfile,$truepath."/$mfile");
- }
- unlink($oldfile);
- ShowMsg("³É¹¦Òƶ¯Îļþ£¡","file_manage_main.php?activepath=$mpath",0,1000);
- return 1;
- }
- else
- {
- ShowMsg("Òƶ¯Îļþ $oldfile -> $truepath/$mfile ʧ°Ü£¬¿ÉÄÜÊÇij¸öλÖÃȨÏÞ²»×㣡","file_manage_main.php?activepath=$mpath",0,1000);
- return 0;
- }
- }
- else
- {
- ShowMsg("¶Ô²»Æð£¬ÄãÒƶ¯µÄ·¾¶²»ºÏ·¨£¡","-1",0,5000);
- return 0;
- }
- }
- /**
- * ɾ³ýĿ¼
- *
- * @param unknown_type $indir
- */
- function RmDirFiles($indir)
- {
- if(!is_dir($indir))
- {
- return ;
- }
- $dh = dir($indir);
- while($filename = $dh->read())
- {
- if($filename == "." || $filename == "..")
- {
- continue;
- }
- else if(is_file("$indir/$filename"))
- {
- @unlink("$indir/$filename");
- }
- else
- {
- $this->RmDirFiles("$indir/$filename");
- }
- }
- $dh->close();
- @rmdir($indir);
- }
- /**
- * »ñµÃijĿ¼ºÏ·û¹æÔòµÄÎļþ
- *
- * @param unknown_type $indir
- * @param unknown_type $fileexp
- * @param unknown_type $filearr
- */
- function GetMatchFiles($indir, $fileexp, &$filearr)
- {
- $dh = dir($indir);
- while($filename = $dh->read())
- {
- $truefile = $indir.'/'.$filename;
- if($filename == "." || $filename == "..")
- {
- continue;
- }
- else if(is_dir($truefile))
- {
- $this->GetMatchFiles($truefile, $fileexp, $filearr);
- }
- else if(preg_match("/\.(".$fileexp.")/i",$filename))
- {
- $filearr[] = $truefile;
- }
- }
- $dh->close();
- }
- /**
- * ɾ³ýÎļþ
- *
- * @param unknown_type $filename
- * @return unknown
- */
- function DeleteFile($filename)
- {
- $filename = $this->baseDir.$this->activeDir."/$filename";
- if(is_file($filename))
- {
- @unlink($filename); $t="Îļþ";
- }
- else
- {
- $t = "Ŀ¼";
- if($this->allowDeleteDir==1)
- {
- $this->RmDirFiles($filename);
- } else
- {
- // ÍêÉÆÓû§ÌåÑ飬by:sumic
- ShowMsg("ϵͳ½ûֹɾ³ý".$t."£¡","file_manage_main.php?activepath=".$this->activeDir);
- exit;
- }
-
- }
- ShowMsg("³É¹¦É¾³ýÒ»¸ö".$t."£¡","file_manage_main.php?activepath=".$this->activeDir);
- return 0;
- }
- }
- //Ŀ¼Îļþ´óС¼ì²âÀà
- class SpaceUse
- {
- var $totalsize=0;
- function checksize($indir)
- {
- $dh=dir($indir);
- while($filename=$dh->read())
- {
- if(!preg_match("#^\.#", $filename))
- {
- if(is_dir("$indir/$filename"))
- {
- $this->checksize("$indir/$filename");
- }
- else
- {
- $this->totalsize=$this->totalsize + filesize("$indir/$filename");
- }
- }
- }
- }
- function setkb($size)
- {
- $size=$size/1024;
- if($size>0)
- {
- list($t1,$t2)=explode(".",$size);
- $size=$t1.".".substr($t2,0,1);
- }
- return $size;
- }
- function setmb($size)
- {
- $size=$size/1024/1024;
- if($size>0)
- {
- list($t1,$t2)=explode(".",$size);
- $size=$t1.".".substr($t2,0,2);
- }
- return $size;
- }
- }