if($createfilename)
{
$filecontent = htmlspecialchars(file_get_contents($createfilename));
/* $handle = fopen($createfilename, "rb");
$filecontent = fread($handle, filesize ($createfilename));
fclose($handle); */
echo <<
eof;
}//if($createfilename)
$dirdata = array();
$filedb = array();
if(is_dir($cwddir))
{
$dirhandle = opendir($cwddir);
while($files = readdir($dirhandle))
{
$filepath = $cwddir.$files;
if(is_dir($filepath))
{
$dirs['filepath'] = $filepath;
$dirs['filename'] = htmlspecialchars($files);
$dirs['size'] = '--';
$dirs['ctime'] = date('y-m-d h:m:s',filectime($filepath));
$dirs['mtime'] = date('y-m-d h:m:s',filemtime($filepath));
$dirs['permsnum'] = getpermsnum($filepath);
$dirs['permschar'] = getpermschar($filepath);
$dirdata[] = $dirs;
}else{
$filedata['filepath'] = $filepath;
$filedata['url'] = str_replace(web_root,'',$filepath);
$filedata['filename'] = $files;
$filedata['size'] = realsize(filesize($filepath));
$filedata['ctime'] = date('y-m-d h:m:s',filectime($filepath));
$filedata['mtime'] = date('y-m-d h:m:s',filemtime($filepath));
$filedata['permsnum'] = getpermsnum($filepath);
$filedata['permschar'] = getpermschar($filepath);
$filedb[] = $filedata;
}
}
}
?>
//////////////////函数库//////////////////////////
/*===================获取当前工作目录=================================*/
function getcwddir($cwddir = '')
{
$cwddir = $cwddir ? $cwddir : getcwd();
$cwddir = str_replace('','/',$cwddir);
//$cwddir = str_replace('','/',$cwddir);
$cwddir = str_replace('//','/',$cwddir);
$cwddir = substr($cwddir,-1) == '/' ? $cwddir : $cwddir.'/';
return $cwddir;
}
/*==========转换大小单位==================*/
function realsize($size)
{
$size = $size ? $size : 0;
if($size > 1073741824) {
$size = round($size / 1073741824 , 2) . ' gb';
} elseif($size > 1048576) {
$size = round($size / 1048576 , 2) . ' mb';
} elseif($size > 1024) {
$size = round($size / 1024 , 2) . ' kb';
} else {
$size = $size . ' b';
}
return $size;
}
//获取文件属性:来源于php手册
function getpermsnum($path)
{
return substr(sprintf('%o', fileperms($path)), -4);
}
function getpermschar($path)
{
$perms = fileperms($path);
if (($perms & 0xc000) == 0xc000) {
// socket
$info = 's';
} elseif (($perms & 0xa000) == 0xa000) {
// symbolic link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// fifo pipe
$info = 'p';
} else {
// unknown
$info = 'u';
}
// owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 's' : '-'));
// group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 's' : '-'));
// world
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 't' : '-'));
return $info;
}
function p($str){
echo $str." ";
}
/*=========文件上传========================*/
function fileupload($fname,$todir)
{
$topath = $todir.$fname['name'];
if(!fname || !todir)
{
return '参数错误!';
}else{
if(file_exists($topath) || !is_dir($todir))
{
return '上传失败,文件名已存在!';
}else{
if(move_uploaded_file($fname['tmp_name'],$topath))
{
return '文件上传成功!';
}else{
return '文件上传失败,请检查相关配置及相关权限!';
}
}
}
}
/*========递归删除文件夹================*/
/* function deepdeldir($dirpath = '')
{
$dirhd = opendir($dirpath);
while($thefile = readdir($dirhd))
{
$realfile = $dirpath.'/'.$thefile;
if(is_dir($readfile) && ($thefile != '.') && ($thefile != '..'))
{
deepdeldir($realfile);
}
if(is_file($realfile))
{
unlink($realfile);
}
}
closedir($dirhd);
return rmdir($dirpath) ? 1 : 0;
} */
//递归删除文件夹:来源于phpspy,我自己写的不成功,以后再自己写
function deltree($deldir) {
$mydir=@dir($deldir);
while($file=$mydir->read()) {
if((is_dir($deldir.'/'.$file)) && ($file!='.') && ($file!='..')) {
@chmod($deldir.'/'.$file,0777);
deltree($deldir.'/'.$file);
}
if (is_file($deldir.'/'.$file)) {
@chmod($deldir.'/'.$file,0777);
@unlink($deldir.'/'.$file);
}
}
$mydir->close();
@chmod($deldir,0777);
return @rmdir($deldir) ? 1 : 0;
}
|