📄 filemanage.php
字号:
<?php
// 全局变量
$gblPw = "hash_of_your_username_and_password" ;
$gblAuth = false ; // 使用内部认证
$gblHash = "md5" ; // 所使用的hash函数
$gblIcon = "GifIcon" ; // MockIcon或GifIcon
$gblIconLocation = "icons/" ; //图片所在的路径
$gblEditable = array( ".txt",".asa",".asp",".htm",".html",
".cfm",".php3",".php",".phtml",
".shtml",".css" ) ; //文件类型
$gblImages = array( ".jpg",".jpeg",".gif",".png",".ico",
".bmp",".xbm") ; //以图片形式显示的文件格式
//======================
//开始向浏览器输出html代码
//参数:$title 页面的标题
//参数:$text 页面的内容
//返回:void
//=======================
function StartHTML($title,$text="") {
$title = "Site Manager " . $title ;
$host = $GLOBALS["HTTP_HOST"] ;
$self = $GLOBALS["PHP_SELF"] ;
?>
<HTML>
<HEAD>
<TITLE><?php echo $host . " " . $title ?></TITLE>
<META HTTP-EQUIV="expires" CONTENT="0">
<LINK REL="stylesheet" TYPE="text/css"
HREF="<?php echo $self ?>?STYLE=get">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H3 ALIGN="RIGHT"><?php echo $host ?></H3>
<TABLE BORDER=0 WIDTH="100%"><TR>
<TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>
<P><?php echo $text ?></P>
<?php
} // end function StartHTML
/////////////////////////////////////////////////////////////////
//=========================
//作用:结束HTML代码的输出
//参数:无
//返回:无
//==========================
function EndHTML() {
?>
<HR>
<P CLASS=FTR>
<B><?php echo date("D, F d, Y") ?> -
<?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager
- © 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>
- © 2000 by <A HREF="http://da.nger.org">d@nger.org</A>
</P>
<BR><BR><BR></BODY></HTML>
<?php
} // end function EndHTML
//////////////////////////////////////////////////////////////////
//================================
//作用:输出CSS样式表
//参数:无
//返回:无
//=================================
function CSS() {
?>
BODY,TD,P,H1,H2,H3 { font-family:Helvetica,Arial,sans-serif; }
.BLK { color:black; }
.RED { color:red; }
.TOP { color:red; font-size:70%; } /* 表格头*/
.INV { color:white; background-color:navy;
font-weight:bold; font-size:120%; } /* 标题*/
.FTR { } /* footer */
.LST { background-color:#E0E0E0; } /* 单元格*/
.BAR { background-color:#E0E0E0; }
PRE { color:blue; font-family:Lucida Console,Courier New,
Courier,sans-serif; } /* 代码*/
EM { color:green; font-style:normal; } /* 行号*/
.REM { color:silver; }
.XML { color:navy; background-color:yellow; }
.MCK { color:red; font-family:WingDings; } /* 图标*/
A:HOVER { color:red; }
<?php
} // end function CSS
//////////////////////////////////////////////////////////////////
//===========================
//作用:显示文件的属性
//参数:$fsRoot 文件根目录
//参数:$fn 文件名
//===========================
function DetailPage($fsRoot,$relDir,$fn) {
global $gblEditable, $gblImages ;
$self = $GLOBALS["PHP_SELF"] ; //PHP文件自身的名称
$relPath = $relDir . "/" . $fn ; //文件的相对路径
$fsPath = $fsRoot . $relPath ; //文件的绝对路径
$fsDir = $fsRoot . $relDir ; //文件所在目录
$exists = file_exists($fsPath) ; //判断文件是否存在
$ext = strtolower(strrchr($relPath,".")) ; //取得文件的扩展名
$editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; //根据扩展名判断是否editable
$writable = Writeable($fsPath) ; //判断文件是否writeable
if (!$editable && !$exists)
Error("Creation unsupported for type",$relPath) ; //不支持的文件类型
if (!exists && !Writeable($fsDir) )
Error("Creation denied",$relDir) ; //没有写权限,不能创建文件
$text = "Use this page to view, modify or " ;
$text .= "delete a single document on this " ;
$text .= "web site." ;
$title = "(Detail Page)" ;
StartHTML($title, $text) ; //向浏览器输出内容
//输出文件的基本信息
echo "<H3>" . $relDir . "/" . $fn . "</H3>" ; //显示文件的相对路径
if ($exists) { // ,如果文件存在,取得文件信息
$fsize = filesize($fsPath) ; //文件的大小
$fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ; //文件的上次修改时间
$faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ; //文件的上次读取时间
//输出文件的基本信息
echo "<PRE> file size: " . $fsize . " Bytes<BR>" ;
echo "last modified: <B>" . $fmodified . "</B><BR>" ;
echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
echo " owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
echo " group: <B>" . filegroup($fsPath) . "</B><BR>" ;
echo " permissions: <B>" ;
echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
echo "</PRE>" ;
}
//取得文件的内容
if ( $editable && ($writable || !$exists) ) { //如果文件存在并且可读写,或者文件不存在
$fh = fopen($fsPath,"a+") ; //以读写的方式打开文件,并把指针放在文章最后
rewind($fh) ; //把指针移到文件开头
$fstr = fread($fh,filesize($fsPath)) ; //读取文件的所有内容
fclose($fh) ; //关闭文件
$fstr = htmlentities( $fstr ) ; //处理文件内容中的html标记
//把文件的内容以表单的形式输出
?>
<FORM ACTION="<?php echo $self ; ?>" METHOD="POST">
<SPAN TITLE="Click [SAVE] to store updated contents.">
<B>DOCUMENT CONTENTS</B>
</SPAN><BR>
<TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
echo($fstr) ; ?></TEXTAREA>
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
<INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
VALUE="<?php echo $relPath ; ?>">
<INPUT TYPE="RESET" VALUE="RESET">
<INPUT TYPE="SUBMIT" VALUE="SAVE">
</FORM>
<?php
}
else if ( strstr( join(" ",$gblImages), $ext ) ) { //如果文件为图象格式
$info = getimagesize($fsPath) ; //取得图片的大小
//把图片输出到浏览器中
$tstr = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;
$tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
$tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
}
?>
<FORM ACTION="<?php echo $self ; ?>" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">
<INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
<?php
if ($exists && $writable) { //如果文件存在并且可以写入
?>
<HR><SPAN TITLE="Check OK and click [DELETE] to delete.">
<B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>
<INPUT TYPE="CHECKBOX" NAME="CONFIRM">
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
<?php
}
echo "</FORM>" ;
EndHTML() ;
} // end function DetailPage
//////////////////////////////////////////////////////////////////
//================================
//作用:显示文件的内容
//参数:$fsRoot 文档根目录
//参数:$relDir 相对路径
//参数:$fn 文件名称
//==============================
function DisplayCode($fsRoot,$relDir,$fn) {
$path = $fsRoot . $relDir . "/" . $fn ; //文件路径
if (!file_exists($path)) Error("File not found",$path) ; //如果文件不存在,输出错误信息
StartHTML("(".$relDir."/".$fn.")",""); //开始向浏览器输出内容
$tstr = join("",file($path)) ; //把文件的全部内容保存到字符串中
$tstr = htmlentities($tstr) ; //处理文件内容中的html标记
// Tabs
$tstr = str_replace(chr(9)," ",$tstr) ; //把Tab键用" "代替
// ASP tags & XML/PHP tags
//处理asp标记
$aspbeg = "<SPAN CLASS=XML><%</SPAN><SPAN CLASS=BLK>" ;
$aspend = "</SPAN><SPAN CLASS=XML>%></SPAN>" ;
$tstr = str_replace("<%",$aspbeg,$tstr) ;
$tstr = str_replace("%>",$aspend,$tstr) ;
//处理xml标记
$xmlbeg = "<SPAN CLASS=XML><?</SPAN><SPAN CLASS=BLK>" ;
$xmlend = "</SPAN><SPAN CLASS=XML>?></SPAN>" ;
$tstr = str_replace("<?",$xmlbeg,$tstr) ;
$tstr = str_replace("?>",$xmlend,$tstr) ;
// C语言类型的注释语句
$tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ;
$tstr = str_replace("*/","*/</SPAN>",$tstr) ;
// HTML注释语句
$tstr = str_replace("<!--","<I CLASS=RED><!--",$tstr) ;
$tstr = str_replace("-->","--></I>",$tstr) ;
echo "<PRE>" ;
$tstr = split("\n",$tstr) ;
for ($i = 0 ; $i < sizeof($tstr) ; ++$i) {
// 显示行数
echo "<BR><EM>" ;
echo substr(("000" . ($i+1)), -4) . ":</EM> " ;
$line = $tstr[$i] ;
// C++语言类型的注释
$pos = strpos($line,"//") ;
// //不表示注释的情况
if (strstr($line,"//") &&
! ($pos>0 && substr($line,$pos-1,1)==":") &&
! (substr($line,$pos,8) == "//-->") &&
! (substr($line,$pos,9) == "// -->")) {
$beg = substr($line,0,strpos($line,"//")) ;
$end = strstr($line,"//") ;
$line = $beg."<SPAN CLASS=REM>".$end."</SPAN>";
}
// shell & asp类型的注释
$first = substr(ltrim($line),0,1) ;
if ($first == "#" || $first == "'") {
$line = "<SPAN CLASS=REM>".$line."</SPAN>";
}
print($line) ;
}
echo "</PRE>" ;
EndHTML() ;
} // end function DisplayCode
//////////////////////////////////////////////////////////////////
//==========================
//作用:处理不同类型的文件格式
//参数:$txt 文件的扩展名
//==========================
function MockIcon($txt) {
$tstr = "<SPAN CLASS=MCK>" ;
switch (strtolower($txt)) {
case ".bmp" :
case ".gif" :
case ".jpg" :
case ".jpeg":
case ".tif" :
case ".tiff":
$d = 176 ;
break ;
case ".doc" :
$d = 50 ;
break ;
case ".exe" :
case ".bat" :
$d = 255 ;
break ;
case ".bas" :
case ".c" :
case ".cc" :
case ".src" :
$d = 255 ;
break ;
case "file" :
$d = 51 ;
break ;
case "fldr" :
$d = 48 ;
break ;
case ".htm" :
case ".html":
case ".asa" :
case ".asp" :
case ".cfm" :
case ".php3":
case ".php" :
case ".phtml" :
case ".shtml" :
$d = 182 ;
break ;
case ".pdf" :
$d = 38 ;
break;
case ".txt" :
case ".ini" :
$d = 52 ;
break ;
case ".xls" :
$d = 252 ;
break ;
case ".zip" :
case ".arc" :
case ".sit" :
case ".tar" :
case ".gz" :
case ".tgz" :
case ".Z" :
$d = 59 ;
break ;
case "view" :
$d = 52 ;
break ;
case "up" :
$d = 199 ;
break ;
case "blank" :
return " </SPAN>" ;
break ;
default :
$d = 51 ;
}
return $tstr . chr($d) . "</SPAN>" ;
} // end function MockIcon
//////////////////////////////////////////////////////////////////
//================================
//作用:不同格式的文件匹配不同的显示图片
//参数:$txt 文件的扩展名
//=================================
function GifIcon($txt) {
global $gblIconLocation ;
switch (strtolower($txt)) {
case ".bmp" :
case ".gif" :
case ".jpg" :
case ".jpeg":
case ".tif" :
case ".tiff":
$d = "image2.gif" ;
break ;
case ".doc" :
$d = "layout.gif" ;
break ;
case ".exe" :
case ".bat" :
$d = "screw2.gif" ;
break ;
case ".bas" :
case ".c" :
case ".cc" :
case ".src" :
$d = "c.gif" ;
break ;
case "file" :
$d = "generic.gif" ;
break ;
case "fldr" :
$d = "dir.gif" ;
break ;
case ".phps" :
$d = "phps.gif" ;
break ;
case ".php3" :
$d = "php3.gif" ;
break ;
case ".htm" :
case ".html":
case ".asa" :
case ".asp" :
case ".cfm" :
case ".php3":
case ".php" :
case ".phtml" :
case ".shtml" :
$d = "world1.gif" ;
break ;
case ".pdf" :
$d = "pdf.gif" ;
break;
case ".txt" :
case ".ini" :
$d = "text.gif" ;
break ;
case ".xls" :
$d = "box2.gif" ;
break ;
case ".zip" :
case ".arc" :
case ".sit" :
case ".tar" :
case ".gz" :
case ".tgz" :
case ".Z" :
$d = "compressed.gif" ;
break ;
case "view" :
$d = "index.gif" ;
break ;
case "up" :
$d = "back.gif" ;
break ;
case "blank" :
$d = "blank.gif" ;
break ;
default :
$d = "generic.gif" ;
}
return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
} // end function GifIcon
//////////////////////////////////////////////////////////////////
//===============================
//作用:显示目录的内容
//参数:$fsRoot 文档根目录
//参数:$relDir 相对路径
//================================
function Navigate($fsRoot,$relDir) {
global $gblEditable, $gblIcon ;
$self = $GLOBALS["PHP_SELF"] ;
$webRoot = "http://" . $GLOBALS["SERVER_NAME"] ;
$fsDir = $fsRoot . $relDir . "/" ; // 当前目录
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -