A.创建目录:
1.主要文件:dede/include/inc_functions.php
2.主要函数:function
MkdirAll($truepath,$mmode);
3.主要代码:
if(!file_exists($truepath)){
mkdir($truepath,$GLOBALS['cfg_dir_purview']);
chmod($truepath,$GLOBALS['cfg_dir_purview']);
return true;
}else{
return true;
}
4.流程:
a.先判断目录是否存在,若存在则执行步骤b,不存在就返回。
b.用系统函数mkdir来创建目录
c.改变权限
B.删除文件:
1.用$filename保存要删除的目录或者文件名。
2.先用is_file($filename)判断要删除的是一个目录还是一个文件.
3.如果是一个文件,用unlink($filename)函数删除文件。
4.如果是一个目录,用dir()
函数打开目录句柄,并返回一个对象.代码如下:
$dh = dir($filename);
5.通过$dh->read()循环读取目录中的文件,如果还是目录,那么递归调用;如果是文件,则删除。具体代码如下:
while($file = $dh->read()) {
if($file == "." || $file == "..")
continue;
else if(is_file("$filename/$file"))
@unlink("$filename/$file");
else
$this->RmDirFiles("$filename/$file");
}
6.关闭$dh句柄
7.用rmdir($filename)移除$filename目录。
C.新建文件
1.传递参数$fmdo和$activepath到file_manage.php页面
2.在file_manage_view.php页面中加载模板,替换标签,显示输入内容页面
3.提交$fmdo,$activepath,$content至file_manage_control.php页面
4.在file_manage_control.php页面,创建文件,把$content写入文件中
5.OK.
D.上传文件
1.传递参数$fmdo和$activepath到file_manage.php页面
2.在file_manage_view.php页面中加载模板,替换标签,显示输入内容页面
3.提交$fmdo,$activepath,$upfile至file_manage_control.php页面
4.在file_manage_control.php页面中,
a.首先判断$upfile是否已经被设置。
b.如果$upfile已经被设置,那么就可以获取文件名称,获取文件在服务器的临时路径等信息。
c.用is_uploaded_file函数来判断文件是否是通过 HTTP POST
上传的,这可以用来确保恶意的用户无法欺骗脚本去访问本不能访问的文件。
d.用move_uploaded_file函数将临时文件夹中的文件移到指定的位置。
e.最后删除掉用unlink删除掉临时文件夹中的文件。
f.显示上传成功的信息。
E.修改文件名称
1.传递参数$fmdo和$activepath和$filename到file_manage.php页面
2.在file_manage_view.php页面中加载模板,替换标签,显示输入内容页面如下:
3.提交$fmdo,$activepath,$oldfilename和newfilename至file_manage_control.php页面
4.在file_manage_control.php页面中,直接调用$fmm的RenameFile($oldname,$newname)方法。
5. RenameFile($oldname,$newname)方法如下:
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;
}
F.新建文件
1.传递参数$fmdo和$activepath和$filename到file_manage.php页面
2.在file_manage_view.php页面中加载模板,替换标签,显示输入内容页面:
3.提交$fmdo,$activepath,$newpath,$content,$filename至file_manage_control.php页面
4.在file_manage_control.php页面,直接调用$fmm的MoveFile($filename,$newpath)方法实现文件的移动。
5.MoveFile($filename,$newpath)方法如下:
function
MoveFile($mfile,$mpath)
{
if($mpath!="" &&
!ereg("\.\.",$mpath))
{
//用oldfile保存旧的文件路径。
$oldfile =
$this->baseDir.$this->activeDir."/$mfile";
//过滤新的路径中的"\\"
$mpath = str_replace("\\","/",$mpath);
//过滤新路径中连续的一个或者多个"//"
$mpath = ereg_replace("/{1,}","/",$mpath);
if(!ereg("^/",$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
失败,可能是某个位置权限不足!","file_manage_main.php?activepath=$mpath",0,1000);
return 0;
}
}else{
ShowMsg("对不起,你移动的路径不合法!","-1",0,5000);
return
0;
}
}