原来的一个在线文件管理系统源代码
侧边栏壁纸
  • 累计撰写 500 篇文章
  • 累计收到 2 条评论

原来的一个在线文件管理系统源代码

admin
2017-04-01 / 0 评论 / 153 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2018年06月25日,已超过2298天没有更新,若内容或图片失效,请留言反馈。
原来的一个在线文件管理系统源代码
<?
###include ("config.inc.php");
$basedir = realpath($db);
$webname = "本程序由黔东明珠网络有限公司免费提供QQ172326362 278910201";
$updatecheck = "yes";
$enable_css = "no";
$enable_logout = "yes";
$allow_move = "yes";
$allow_down = "yes";
$allow_copy = "yes";
$allow_touch = "no";
$allow_rename = "yes";
$allow_edit = "yes";
$allow_chmod = "yes";
$allow_delete = "yes";
$allow_upload = "yes";
$allow_create_dir = "yes";
$allow_create_file = "yes";
$allow_display_env = "yes";
$not_allowed = "该操作不被禁止,请和你的网络管理员联系。";
$version = "2.0";
############### Size for textarea
if($enable_css == "yes")
	{
	$textrows = "27";
	$textcols = "160";
	}
else
	{
	$textrows = "20";
	$textcols = "100";
	}
############### If $wdir (working directory) isn't specified, set it as a slash (/)
if(!$wdir) $wdir="/";
############### HTML ender
$html_ender = "</td></tr><tr><td colspan=\"2\"><hr></td></tr><tr><th colspan=\"2\" bgcolor=\"#4C4C99\"><font size=\"-1\" color=\"white\" face=\"Arial,宋体\">黔东明珠网络有限公司免费空间管理系统测试版</font></th></tr></table></body></html>";
############### Calculate image size
function imagesize()
	{
	$size = GetImageSize("$image");
	}
############### HTML header
function html_header(){
	global $basedir;
	global $wdir;
	global $lastaction;
	global $version;
	global $HTTP_REFERER;
	global $action;
	global $webname;
	global $display;
	global $file;
	global $browse;
	global $raw;
	global $image;
	global $fileurl;
	global $enable_css;
	global $allow_display_env;
	global $enable_logout;
	echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3c.org/TR/REC-html40/loose.dtd\">";
	echo "<HTML>";
	echo "<HEAD>";
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">";
	echo "<TITLE>黔东明珠Webedit $version ($webname)</TITLE>";
	############### Cascaded Style Sheets
	if($enable_css == "yes")
		{
		?>
		<STYLE  TYPE="text/css">
		<!--
		input
			{
			font-family : Arial,宋体;
			font-size : 9;
			color : #000033;
			font-weight : normal;
   			border-color : #999999;
   			border-width : 1;
   			background-color : #FFFFFF;
			}
		textarea
			{
			font-family : Arial,宋体;
			font-size : 9;
			color : #000033;
			font-weight : normal;
   			border-color : #999999;
	   		border-width : 1;
   			background-color : #FFFFFF;
			}
		-->
		</style>
		<?
		}
	echo "</HEAD>";
	echo "<BODY bgcolor=\"#C0C0C0\" link=\"#4C4C99\" vlink=\"#4C4C99\" alink=\"#4C4C99\">";
	echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"600\">";
	echo "<tr>";
	echo "	<th colspan=\"2\" width=\"100%\" bgcolor=\"#4C4C99\">";
	if($allow_display_env == "yes")
		{
		echo "	 <A HREF=\"$PHP_SELF?action=env&wdir=$wdir\"><img src=\"./images/env.gif\" alt=\"环境变量\" border=\"0\" width=\"16\" height=\"15\"></A>";
		}
	echo "	 &nbsp;<font size=\"4\" color=\"white\" face=\"Arial,宋体\">黔东明珠Webedit$version</font> &nbsp";
if($enable_logout == "yes")
{
		echo "	 <A HREF=\"$PHP_SELF?action=help&wdir=$wdir\"><img src=\"./images/env.gif\" alt=\"检查版本或提意见\" border=\"0\" width=\"16\" height=\"15\"></A>";
		}
			echo "	</th>";
	echo "</tr>";
	echo "<tr>";
	echo " <td width\"15%\" align=\"left\"><A HREF=\"$PHP_SELF?action=root\"><font size=\"4\" face=\"Arial,宋体\">返回根目录</font></a>";
echo ".          .<A HREF=\"quit.php\" title=\"退出\"><font size=\"4\" face=\"Arial,宋体\">退出</font></A>";
#########if ($allow_down == "yes")
######{
echo " .             .<A HREF=\"unzip.php\" title=\"打包上传\" target=\"_blank\"><font size=\"4\" face=\"Arial,宋体\">打包上传</font></A>";
#########}
	echo ".           .<A HREF=\"$PHP_SELF?wdir=$wdir\" title=\"刷新当前目录\"><font size=\"4\" face=\"Arial,宋体\">刷新</font></a></td>";
	echo "</tr>";
	echo "<tr>";
	echo " <td colspan=\"2\"><hr></td>";
	echo "</tr>";
	echo "<tr>";
	############ We want a BACK link when viewing pictures and raw text.
	if($action == "show")
		{
		echo " <td width=\"50%\" nobreak><b><font size=\"3\" color=\"#4C4C99\" face=\"Arial,宋体\">$lastaction</font></b></td>";
		echo " <td width=\"50%\" nobreak align=\"right\"><b><font size=\"3\" color=\"#4C4C99\" face=\"Arial,宋体\"><a href=\"$HTTP_REFERER\" title=\"返回上一个页面\">返回</a></font></b></td>";
		}
	############ We dont want a BACK link
	else
		{
		echo " <td colspan=\"2\"><b><font size=\"3\" color=\"#4C4C99\" face=\"Arial,宋体\">$lastaction</font></b></td>";
		}
	echo "<tr>";
	echo "<td colspan=\"2\"><hr><td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td colspan=\"2\">";
}
############ File size calculations
function display_size($file){
$file_size = filesize($file);
if($file_size >= 1073741824)
 	{
        $file_size = round($file_size / 1073741824 * 100) / 100 . "g";
	}
elseif($file_size >= 1048576)
	{
        $file_size = round($file_size / 1048576 * 100) / 100 . "m";
	}
elseif($file_size >= 1024)
	{
        $file_size = round($file_size / 1024 * 100) / 100 . "k";
	}
else{
        $file_size = $file_size . "b";
	}
return $file_size;
}
############ List the files function
function list_files()
	{
	global $basedir;
	global $wdir;
	global $single;
	global $key;
	global $allow_move;
	global $allow_chmod;
	global $allow_create_file;
	global $allow_create_dir;
	global $allow_upload;
	global $allow_touch;
	global $allow_delete;
	################## Load directory into array
	$handle=opendir(".");
	while ($file = readdir($handle))
		{
		if(is_file($file)) $filelist[] = $file;
		}
	closedir($handle);
	############### List files
	if($filelist)
		{
		############### Sort the filelist alphabetically
		asort($filelist);
		while (list ($key, $file) = each ($filelist))
			{
			############### Registered filetypes. You can add more filetypes here at wish..
			############### Check what fileformat it is and give it the correct icon and attributes
			$ext = strrchr ( $file , "." );
			############### Image
			if((!strcasecmp ($ext, ".gif")) || (!strcasecmp ($ext, ".jpg")) || (!strcasecmp ($ext, ".png")) || (!strcasecmp ($ext, ".bmp")) || (!strcasecmp ($ext, ".jpeg")))
				{
				$icon = "<IMG SRC=\"./images/image.gif\" alt=\"图像\" border=\"0\" width=\"16\" height=\"16\">";
				$browse = "0";
				$raw = "0";
				$image = "1";
				}
			############### Textfile
			elseif(!strcasecmp ($ext, ".txt"))
				{
				$icon = "<IMG SRC=\"./images/text.gif\" alt=\"文本\" border=\"0\" width=\"13\" height=\"16\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### Audiofile
			elseif((!strcasecmp ($ext, ".wav")) || (!strcasecmp ($ext, ".mp2")) || (!strcasecmp ($ext, ".mp3")) || (!strcasecmp ($ext, ".mp4")) || (!strcasecmp ($ext, ".vqf")) || (!strcasecmp ($ext, ".midi")) || (!strcasecmp ($ext, ".mid")))
				{
				$icon = "<IMG SRC=\"./images/audio.gif\" alt=\"音频\" border=\"0\" width=\"16\" height=\"16\">";
				$browse = "0";
				$raw = "0";
				$image = "0";
				}
			############### Webscript
			elseif((!strcasecmp ($ext, ".phps")) || (!strcasecmp ($ext, ".php")) || (!strcasecmp ($ext, ".php2")) || (!strcasecmp ($ext, ".php3")) || (!strcasecmp ($ext, ".php4")) || (!strcasecmp ($ext, ".phtml")) || (!strcasecmp ($ext, ".asp")) || (!strcasecmp ($ext, ".asa")) || (!strcasecmp ($ext, ".cgi")) || (!strcasecmp ($ext, ".shtml")) || (!strcasecmp ($ext, ".pl")))
				{
				$icon = "<IMG SRC=\"./images/webscript.gif\" alt=\"WEB程序\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### Apache Webserver security settings
			elseif(!strcasecmp ($ext, ".htaccess"))
				{
				$icon = "<IMG SRC=\"./images/security.gif\" alt=\"Apache服务器安全设置\" border=\"0\" width=\"15\" height=\"16\">" ;
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### Web page
			elseif ((!strcasecmp ($ext, ".html")) || (!strcasecmp ($ext, ".htm")))
				{
				$icon = "<IMG SRC=\"./images/webpage.gif\" alt=\"网页\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### WAP page
			elseif(!strcasecmp ($ext, ".wml"))
				{
				$icon = "<IMG SRC=\"./images/webscript.gif\" alt=\"WAP页\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### Compressed file
			elseif((!strcasecmp ($ext, ".zip")) || (!strcasecmp ($ext, ".tar")) || (!strcasecmp ($ext, ".rar")) || (!strcasecmp ($ext, ".gz")))
				{
				$icon = "<IMG SRC=\"./images/text.gif\" alt=\"压缩文件\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "0";
				$image = "0";
				}
			############### Unknown
			else
				{
				$icon = "<IMG SRC=\"./images/text.gif\" alt=\"未知文件类型\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}
			############### List the file(s)
			$filename=$basedir.$wdir.$file;
			$fileurl=rawurlencode($wdir.$file);
			$lastchanged = filectime($filename);
			$changeddate = date("Y-d-m H:i:s", $lastchanged);
			echo "<TR>";
			echo "<TD align=\"center\" nobreak>";
			############### Make the fileicon clickable for quickviewing
			if($raw == "1")
				{
				echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&object=file&browse=$browse&raw=$raw\">";
				}
			if($image == "1")
				{
				echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image&object=file&browse=$browse&raw=$raw\">";
				}
			echo "$icon</TD>\n";
			echo "<TD nobreak><font size =\"-1\" face=\"Arial,宋体\">" . htmlspecialchars($file) . "</font></TD>\n";
			echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial\">" . display_size($filename) . "</font></TD>";
			echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial\">" . $changeddate . "</font></TD><TD align=\"right\">";
			############### CHMOD file?
			if($allow_chmod == "yes")
				{
				echo "<A HREF=\"$PHP_SELF?action=chmod&wdir=$wdir&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\" title=\"改变 $file 的权限级别\">";
				}
			echo "<font size =\"-1\" face=\"Arial,宋体\">";
			printf("%o", (fileperms($filename)) & 0777);
			echo "</font>";
			if($allow_chmod == "yes")
				{
				echo "</A>";
				}
			echo "</TD><TD nobreak>";
			############### Move file?
			if($allow_move == "yes")
				{
				echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl&object=file&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"./images/move.gif\" alt=\"移动、改名或者复制 $file\" border=\"0\" width=\"15\" height=\"15\"></A> ";
				}
			############### Touch file?
			if($allow_touch == "yes")
				{
				echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"/images/touch.gif\" alt=\"Touch $file\" border=\"0\" width=\"12\" height=\"16\"></A> ";
				}
			############### Delete file?
			if($allow_delete == "yes")
				{
				echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"./images/delete.gif\" alt=\"删除 $file\" border=\"0\" width=\"20\" height=\"16\"></A> ";
				}
			############### If the file can be browsed, give it the browse icon
			if($browse == "1")
				{
				echo " <A HREF=\".$wdir$file\"><img src=\"./images/browse.gif\" alt=\"浏览 $file\" border=\"0\" width=\"16\" height=\"16\"></A> ";
				}
			############### If the file can be edited, give it the edit icon
			if($raw =="1")
				{
				echo " <A HREF=\"$PHP_SELF?wdir=$wdir&action=edit&display=1&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"./images/edit.gif\" alt=\"编辑 $file\" border=\"0\" width=\"16\" height=\"16\"></A> ";
				}
			}
		}
	}
############ List the directory function
function displaydir()
	{
	global $file;
	global $basedir;
	global $wdir;
	global $allow_create_file;
	global $allow_create_dir;
	global $allow_upload;
	global $allow_touch;
	global $allow_delete;
	global $allow_move;
	global $single;
	############### Draw the head table
	if(isset($single))
		{
		echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" align=\"center\">";
		}
	else
		{
		echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";
		}
	echo "<tr>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">类型</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">名 称</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">大小</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">修改时间</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">移改</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"Arial,宋体\">操 作</font></th>";
	echo "</tr>";
	################## Load directory into array
	if(!isset($single))
		{
		chdir($basedir . $wdir);
		$handle=opendir(".");
		while ($file = readdir($handle))
			{
			if(is_dir($file)) $dirlist[] = $file;
			}
		closedir($handle);
		############### List directories first
		if($dirlist)
			{
			############### Sort alphabetically
			asort($dirlist);
			############### Walk through array
			while (list ($key, $file) = each ($dirlist))
				{
				################## Skip the tiresome "."
				if (!($file == "."))
					{
					$filename=$basedir.$wdir.$file;
					$fileurl=rawurlencode($wdir.$file);
					$lastchanged = filectime($filename);
					$changeddate = date("Y-d-m H:i:s", $lastchanged);
					echo "<TR>";
					############### Print PARENT arrow
					if($file == "..")
						{
						$downdir = dirname("$wdir");
						echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"./images/parent.gif\" alt=\"返回上一级目录(文件夹)\" border=\"0\" width=\"20\" height=\"16\"></a></TD>\n";
						echo "<TD></TD>\n";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial,宋体\">" . display_size($filename) . "</font></TD>";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial,宋体\">" . $changeddate . "</font></TD><TD align=\"right\">";
						#########printf("%o", (fileperms($filename)) & 0777);
						echo "</TD><TD nobreak>";
						echo "<A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"./images/parent.gif\" alt=\"Parent directory\" border=\"0\" width=\"20\" height=\"16\"></A> ";
						}
					############### List the directory
					else
						{
						$lastchanged = filectime($filename);
						echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\"><img src=\"./images/folder.gif\" alt=\"改变工作文件夹到 $file\" border=\"0\" width=\"15\" height=\"13\"></a></TD>\n";
						echo "<TD nobreak><font size =\"-1\" face=\"Arial,宋体\">" . htmlspecialchars($file) . "</font></TD>\n";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial,宋体\">" . display_size($filename) . "</font></TD>";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"Arial,宋体\">" . $changeddate . "</font></TD><TD align=\"right\">";
						########echo "<A HREF=\"$PHP_SELF?action=chmod&file=$filename\" title=\"改变 $file 的权限级别\"><font size =\"-1\" face=\"Arial,宋体\">";
						########printf("%o", (fileperms($filename)) & 0777);
						########echo "</A>";
						echo "</font></TD><TD nobreak>";
						############### Move directory?
						if($allow_move == "yes")
							{
							echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"./images/move.gif\" alt=\"改名 $file\" border=\"0\" width=\"15\" height=\"15\"></A> ";
							}
						############### Touch directory?
						if($allow_touch == "yes")
							{
							echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"./images/touch.gif\" alt=\"Touch $file\" border=\"0\" width=\"12\" height=\"16\"></A> ";
							}
						############### Delete directory?
						if($allow_delete == "yes")
							{
							echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"./images/delete.gif\" alt=\"删除 $file\" border=\"0\" width=\"20\" height=\"16\"></A> ";
							}
						}
					}
				}
			}
		list_files();
		echo "</TD></TR>\n";
		echo "</TABLE>";
		############### Display forms for different actions
		echo "<table border=\"0\" width=\"100%\">";
		echo "<TR><TD colspan=\"2\"><hr></td>";
		############### Upload file
		if($allow_upload  == "yes")
			{
			echo "<TR><TD><font size =\"-1\" face=\"Arial,宋体\">上传文件</font></td><td>";
			echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT NAME=\"userfile\" TYPE=\"file\" size=\"40\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"upload\" VALUE=\"上传\"></TD></TR>";
			echo "</FORM>";
			}
		############### Create directory
		if($allow_create_dir == "yes")
			{
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
			echo "<TR><TD><font size =\"-1\" face=\"Arial,宋体\">创建文件夹</font></td><td>";
			echo "<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"mkdir\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"mkdir\"  VALUE=\"创建\"></TD></TR>";
			echo "</FORM>";
			}
		############### Create file
		if($allow_create_file == "yes")
			{
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
			echo "<TR><TD><font size =\"-1\" face=\"Arial,宋体\">创建文件</font></td><td>";
			echo "<INPUT TYPE=\"TEXT\" NAME=\"file\" size=\"40\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\"> ";
			echo "<input type=\"checkbox\" name=\"html\" value=\"yes\"><font size =\"2\" face=\"Arial,宋体\">(html 模板)</font> ";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"createfile\" VALUE=\"创建\">";
			echo "</TD></TR>";
			echo "</FORM>";
			}
		echo "</TABLE>";
		}
	else
		{
		list_files();
		}
	}
#########################################################################################################
############### The user pressed CANCEL, set the $action to nothing
if($cancel) $action="";
############### User has entered .. as directory. Potential security breach. Deny access.
$regexp="\\.\\.";
if (ereg( $regexp, $file, $regs )| ereg( $regexp, $wdir,$regs ))
{
    $lastaction = "错误:文件夹不可以包含 \"..\"";
    html_header();
    echo $html_ender;
    exit;
}
############### Upload file
if($upload)
	{
	copy($userfile,$basedir.$wdir.$userfile_name);
		$lastaction = "已经成功上传文件 $userfile_name 到文件夹 $wdir";
		html_header();
		displaydir();
		echo $html_ender;
		exit;
	}
#########################################################################################################
############### Begin actions code
switch ($action)
{
#########################################################################################################
############### No $action variable? Display initial page
	case "":
		$lastaction = "文件夹列表";
		html_header();
		displaydir();
		echo $html_ender;
		break;
#########################################################################################################
############### Help
	case "help":
		$lastaction = "检查更新";
		html_header();
		if($updatecheck == yes)
			{
			############### Check to see if there is an update
			$filename = "./webedit/webedit.dat";
  			$fd = fopen ($filename, "r");
  			$contents = fread ($fd, 1024);
  			fclose ($fd);
			############### There is. Give the user information about this
			if($version < $contents)
				{
				echo"<b>注意<br>";
				echo"本管理系统发现一个可用的更新<br>";
				echo"您现在使用的版本是$version, 而最新版本是 $contents 。<br>";
				echo"你当前使用的版本已经过时了,为了安全起见,请访问 www.qdmz.com <a href=\"http://www.qdmz.com/\">网站</a> 下载新版</b><br>";
				echo "如果你对本程序有什么好的意见或建议,请到这<A HREF=\"$PHP_SELF?action=bugreport\">提交</a>。";
				echo"<hr>";
				}
if ($version == $contents){
echo"您现在使用的版本$version 是最新版本,暂无更新或与吴朝晖联系索取最新版。<br>";
echo "如果你对本程序有什么好的意见或建议,请到这<A HREF=\"$PHP_SELF?action=bugreport\">提交</a>。";
}
if ($version > $contents){
echo"<b>注意</b><br>";
echo"您现在使用的程序版本$version 不是正版产品,为了安全起见,请访问 www.qdmz.com <a href=\"http://www.qdmz.com/\">网站</a> 下载最新正版</b><br>";
echo "如果你对本程序有什么好的意见或建议,请到这<A HREF=\"$PHP_SELF?action=bugreport\">提交</a>。";
}
			}
		echo $html_ender;
		break;
#########################################################################################################
############### User pressed ROOT.. Change to root dir
	case "root":
   		$wdir="/";
		$lastaction = "返回根目录";
		html_header();
		displaydir();
		echo $html_ender;
		break;
#########################################################################################################
############### Display PHP env
	case "env":
		if($allow_display_env == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			displaydir();
			echo $html_ender;
			}
		else
			{
	   		$lastaction = "显示PHP环境变量";
			html_header();
			phpinfo();
			echo $html_ender;
			}
		break;
#########################################################################################################
############### Change directory
	case "chdr":
		$wdir=$file."/";
		$lastaction = "已改变当前目录到 $wdir";
		html_header();
		displaydir();
		echo $html_ender;
		break;
#########################################################################################################
############### Touch object (create a new timestamp)
	case "touch":
		if($allow_touch == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			displaydir();
			echo $html_ender;
			}
		else
			{
			touch($basedir.$touchfile);
			$lastaction = "Touched $touchfile";
			html_header();
			displaydir();
			echo $html_ender;
			}
		break;
#########################################################################################################
############### Bug report form
	case "bugreport":
		if ($send)
			{
 			$lastaction = "BUG 意见或建议已提交,谢谢你。";
			html_header();
			mail("admin@qdmz.com","Bug report","Name: $name \nVersion: $version \n\nProblem: $problem");
			echo "<h3><a href=\"$PHP_SELF?action=help&wdir=$wdir\">Back to help</a></h3>";
			}
		else
			{
			$lastaction = "BUG报告,意见或建议提交表格";
			html_header();
			?>
			<table>
			<form action="<? echo "$PHP_SELF?action=bugreport&wdir=$wdir&send=1"; ?>" method="POST">
			<tr>
				<td>您的名字:</td>
				<td><input name="name" size="24" maxlength="30"></td>
			</tr>
			<tr>
				<td>您的电子邮件:</td>
				<td><input name="email" size="24" maxlength="30"></td>
			</tr>
			<tr>
				<td>问题描述:</td>
				<td><textarea name="problem" cols="30" rows="5"></textarea></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit" value="Send"></td>
			</tr>
			</table>
			<?
			}
		echo $html_ender;
		break;
#########################################################################################################
############### Delete file or directory
	case "del":
		############### The user has comfirmed the deletion
		if ($confirm)
			{
			############### Object is a directory
			if(is_dir($basedir.$file))
				{
kill_dir($basedir.$file);
if (rmdir($basedir.$file)) $lastaction = "目录 $file 已成功删除";
else $lastaction =  "目录 $file 删除失败";
#######$result = @rmdir($basedir.$file);
#########			if($result ==0)
###########			{
#########				$lastaction = "无法删除这个文件夹,必须是空文件夹才可以被删######除。";
########			}
}
			############### Object is a file
			else
				{
				unlink($basedir.$file);
				$lastaction = "文件 $file 已删除";
}
			html_header();
			displaydir();
			}
		############### Prompt the user for confirmation
		else
			{
			if($raw == "1")
				{
				$lastaction = "您真的要删除吗?<br><A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\" title=\"查看源文件\">$file</a>?";
				}
			elseif($image == "1")
				{
				$lastaction = "您真的要删除吗?<br><A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"查看这个图像\">$file</a>?";
				}
			else
				{
				$lastaction = "您真的要删除吗?<br>$file?";
				}
			html_header();
			echo "<center><b><font size =\"5\" face=\"Arial,宋体\"><A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$file&confirm=1\">YES!</A></font><br>";
			echo "<p><font size =\"5\" face=\"Arial,宋体\"><A HREF=\"$PHP_SELF?wdir=$wdir\">NO!</A></font><br><b></center>";
			}
		echo $html_ender;
		break;
#########################################################################################################
############### Change permission level
	case "chmod":
		############### The user has confirmed
		if ($confirm)
			{
			$level = "0";
			$level .= $owner;
			$level .= $group;
			$level .= $public;
			$showlevel = $level;
			$level=octdec($level);
			chmod($basedir.$file,$level);
			$lastaction = "文件 $file 的权限级别已改为 $showlevel";
			html_header();
			displaydir();
			}
		############### Prompt the user for confirmation
		else
			{
			$lastaction = "改变文件 $file 的权限级别";
			html_header();
			echo "<font face=\"Arial,宋体\"><center><h4>Current level: ";
			printf("%o", (fileperms($basedir.$file)) & 0777);
			echo "</h4><FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			function selections($type)  //  type: 0 Owner, 1 Group, 2 Public
				{
				echo "<option value=\"0\""; if (substr($GLOBALS["perm"], $type, 1)=="0") echo "selected"; echo ">0 - 没有权限";
				echo "<option value=\"1\""; if (substr($GLOBALS["perm"], $type, 1)=="1") echo "selected"; echo ">1 - 执行";
				echo "<option value=\"2\""; if (substr($GLOBALS["perm"], $type, 1)=="2") echo "selected"; echo ">2 - 写入 ";
				echo "<option value=\"3\""; if (substr($GLOBALS["perm"], $type, 1)=="3") echo "selected"; echo ">3 - 执行和写入";
				echo "<option value=\"4\""; if (substr($GLOBALS["perm"], $type, 1)=="4") echo "selected"; echo ">4 - 读取";
				echo "<option value=\"5\""; if (substr($GLOBALS["perm"], $type, 1)=="5") echo "selected"; echo ">5 - 执行和读取";
				echo "<option value=\"6\""; if (substr($GLOBALS["perm"], $type, 1)=="6") echo "selected"; echo ">6 - 写入和读取";
				echo "<option value=\"7\""; if (substr($GLOBALS["perm"], $type, 1)=="7") echo "selected"; echo ">7 - 写入、执行和读取";
				echo "</select>";
				}
			$perm = sprintf ("%o", (fileperms($basedir.$file)) & 0777);  // Definition of a variable containing the file permissions
			echo "<p><h4>用户<br>";
			echo "<select name=\"owner\">";
			selections(0);
			echo "<p>组<br>";
			echo "<select name=\"group\">";
			selections(1);
			echo "<p>公众<br>";
			echo "<select name=\"public\">";
			selections(2);
			echo "</h4>";
			echo "<p>";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"改变\">\n";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"放弃\">\n";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"chmod\">\n";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "</FORM>";
			echo "</center>";
			}
		echo $html_ender;
		break;
#########################################################################################################
############### Move file
	case "move":
		############### The user has confirmed renaming/moving/copying of the object
		if($confirm && $newfile)
 			{
			############### The destination object exists
    			if(file_exists($basedir.$newfile))
				{
				$lastaction = "目标文件已经存在。";
				}
			else
				{
				if($do == copy)
					{
					copy($basedir.$file,$basedir.$newfile);
					$lastaction = "复制完成\n$file → $newfile";
					}
				else
					{
					rename($basedir.$file,$basedir.$newfile);
					$lastaction = "移动/改名完成\n$file → $newfile";
					}
				}
			html_header();
			displaydir();
    			echo $html_ender;
			}
		############### Prompt the user for destination name and action
		else
			{
			if($object == "file")
				{
				if($raw == "1")
					{
					$lastaction = "移动、改名或者复制文件 <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\" title=\"查看源文件\">$file</a>";
					}
				elseif($image == "1")
					{
					$lastaction = "移动、改名或者复制文件 <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"查看图像\">$file</a>";
					}
				else
					{
					$lastaction = "移动、改名或者复制文件 $file";
					}
				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<select name=\"do\">";
				echo "<option value=\"copy\">复制";
				echo "<option value=\"move\">移动/改名";
				echo "</select> ";
				echo "($file)";
				echo "<h4>↓</h4>";
				echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"40\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<p>";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"确定\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"放弃\">\n";
				echo "</FORM>";
				echo $html_ender;
				}
			else
				{
				$lastaction = "改名 $file";
				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<h4></h4>";
				echo "$file";
				echo "<h4>↓</h4>";
				echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"40\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<p>";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"确定\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"放弃\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"do\" VALUE=\"移动\">\n";
				echo "</FORM>";
				echo $html_ender;
				}
			}
		break;
#########################################################################################################
############### Edit file
	case "edit":
		############### Function for saving the file.
		function savefile()
			{
			global $basedir;
			global $file;
			global $code;
			html_header();
			$fp=fopen($basedir.$file,"w");
			fputs($fp,stripslashes($code));
			fclose($fp);
			}
		function buttons()
			{
			global $file;
			global $wdir;
			echo "<center>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"edit\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"RESET\" VALUE=\"重新加载\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"save\" VALUE=\"保存\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"saveexit\" VALUE=\"保存并返回\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"放弃并返回\"> ";
			echo "</center><BR>\n";
			}
		############### The user is done editing. Return to main screen
		if($saveexit)
   			{
    			$lastaction = "编辑 <a href=\"$file\" title=\"查看文件\">$file</a>";
			savefile();
			displaydir();
			}
		############### Save the file, but continue editing.
		if($save)
   			{
    			$lastaction = "保存 <a href=\"$file\" title=\"查看文件\">$file</a>, 继续编辑.";
			savefile();
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			$fp=fopen($basedir.$file,"r");
			$contents=fread($fp,filesize($basedir.$file));
			echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
			echo htmlspecialchars($contents);
			echo "</TEXTAREA><BR>\n";
			echo "<center>";
			buttons();
			echo "</FORM>";
			}
		############### Display file in textarea
		if($display)
			{
			if($raw == "1")
				{
				$lastaction = "编辑 <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$file&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\" title=\"查看源文件\">$file</a>";
				}
			elseif($image == "1")
				{
				$lastaction = "编辑 <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"查看图像\">$file</a>";
				}
			else
				{
				$lastaction = "编辑 $file";
				}
			html_header();
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			$fp=fopen($basedir.$file,"r");
			$contents=fread($fp,filesize($basedir.$file));
			echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
			echo htmlspecialchars($contents);
			echo "</TEXTAREA><BR>\n";
			buttons();
			echo "</FORM>";
			}
		echo $html_ender;
		break;
#########################################################################################################
############### Display file
	case "show":
		############### Display file in textformat
		$filelocation = $wdir.$file;
		$lastaction = "显示文件 $file";
		html_header();
		############### It is a picture, display it. The filename needs to be either relative to the current document, or an absolute filesystem path.
		if($image == "1")
			{
			$size = GetImageSize($DOCUMENT_ROOT.$file);
			echo "<center><img src=\"$file\" $size[3]></center>";
			}
		############### It is text, display it.
		else
			{
			$single = "yes";
#			displaydir();
			echo"<hr><br>";
			show_source($basedir.$file);
			}
		echo $html_ender;
		break;
#########################################################################################################
############### Create directory
	case "mkdir":
		############### Is the action allowed?
		if($allow_create_dir == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			}
		else
			{
			############### The directory already exists.
			if(file_exists($basedir.$wdir.$mkdirfile))
				{
				$lastaction = "文件夹 $wdir$mkdirfile 已经存在。";
				html_header();
				}
			############### Create directory
			else
				{
				$lastaction = "文件夹 $wdir$mkdirfile 创建成功!";
				html_header();
				mkdir($basedir.$wdir.$mkdirfile,0755);
				}
			displaydir();
			echo $html_ender;
			}
		break;
#########################################################################################################
############### Create file
	case "createfile":
		$filelocation = $wdir.$file;
		############### The user is done editing. Return to main screen
		if($done == "1")
   			{
			$lastaction = "创建文件 $file";
			html_header();
#			if($convert == "yes")
#   				{
#				$code = str_replace ("\n", "<BR>");
#				}
			$fp=fopen($basedir.$filelocation,"w");
			fputs($fp,stripslashes($code));
      			fclose($fp);
			displaydir();
			}
		############### Display a textarea that will be the file
		else
			{
   			############### The file allready exists
   			if(file_exists($basedir.$filelocation))
   				{
   				$lastaction = "文件 $file 已经存在。";
				html_header();
				displaydir();
				}
			############### Give the user a textarea to write the contents of file
			else
				{
				$lastaction = "创建文件 $file";
				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"done\" VALUE=\"1\">\n";
				echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
				############### The user selected to use a html template. Put it inside the textarea
				if(isset($html))
					{
					echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n";
					echo "<html>\n";
					echo "<head>\n";
					echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n";
					echo "<title>未命名</title>\n";
					echo "</head>\n";
					echo "<body>\n\n";
					echo "</body>\n";
					echo "</html>";
					}
				echo "</TEXTAREA><BR>\n";
				echo "<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"创建\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"取消\"><br>";
				$ext = strrchr ( $file , "." );
				if(!strcasecmp ($ext, ".txt"))
					{
					echo "<input type=\"checkbox\" name=\"convert\" value=\"yes\"><font size =\"-2\" face=\"Arial,宋体\">(将换行改为BR)</font> ";
					}
				echo "</center><BR>\n</FORM>";
				}
			}
		echo $html_ender;
		break;
}
function kill_dir($dir) {
$dirhandle=opendir($dir);
while($file_name=readdir($dirhandle)) {
if ($file_name!="." && $file_name!="..") {
if (is_dir("$dir/$file_name")) {
kill_dir($dir."/".$file_name);
rmdir("$dir/$file_name");
} else {
unlink("$dir/$file_name");
}
}
}
closedir($dirhandle);
}
?>
原来的一个在线文件管理系统源代码
      
0

评论 (0)

取消