[原創]php+ajax實現模擬Win文件管理系統
//本教程由本站原創,轉載請注明來處
作者:www.drise.cn
QQ:271728967//
接上面我們來看dir.php文件代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
<script language="javascript" src="js/js.js"></script>
<style type="text/css">
<!--
.folder{
height:97px;
width:99px;
border:1px solid #e4e4e4;
text-align:center;
float:left;
margin:20px;
padding-top:15px;
color:#E4E4E4
}
#t{
height:97px;
width:99px;
border:1px solid #e4e4e4;
text-align:center;
float:left;
margin:20px;
padding-top:15px;
color:#E4E4E4;
display:none;
}
p{
text-align:center;
color:#000000;
font-size:12px;
width:90px;
white-space:nowrap;
text-overflow:ellipsis;
-o-text-overflow:ellipsis;
overflow: hidden;
margin-top:15px;
}
input{
width:80px;
border:1px solid #000;
height:18px;
}
#info{
border:1px solid #FF9933;
background-color:#FFFFE1;
display:none;
font-size:12px;
padding-top:7px;
text-align:left;
padding-left:10px;
width:300px;
}
li{
list-style-type:none;
list-style:none;
padding-left:0px;
font-size:12px;
cursor:default;
padding-top:2px;
}
#Layer1{
border:1px solid #28B9FF;
background-color:#ECF9FF;
padding:10px;
padding-top:20px;
line-height:30px;
height:20px;
display:none;
}
.up{width:300px; height:24px;border:1px;}
.bt{width:70px; height:24px;}
#tool{ height:47px; width:98%; margin:0px auto; background-image:url(image/tool_bg.jpg); margin-top:0px;padding-top:0px;padding-left:10px;}
.ta{display:inline-block;width:72px;height:30px; line-height:30px; text-align:center;margin-top:2px; color:#4D4D4D; text-decoration:none}
a.ta:hover{background:url("image/tool_if.gif") no-repeat ; height:30px;}
.aa{ background:url("image/tool_if.gif") no-repeat ; height:40px;}
.bb{ background:#fff;}
body {
margin-left: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body >
<?php
$dir_path=isset($_GET['url'])?$_GET['url']:'..';
//$totallen = strlen($dir_path);
//$sublen = strlen(substr($dir_path,strrpos($dir_path,"/")));
$lastdir = substr($dir_path,0,strlen($dir_path)-strlen(substr($dir_path,strrpos($dir_path,"/"))));
Tool($dir_path,$lastdir);
CheckDir($dir_path);
//echo "<br>";
//echo substr($dir_path,0,(strlen($dir_path)-strrpos($dir_path,"/")+1));
function CheckDir($dir_path){// 這個函數是檢查並顯示當前目錄下的文件及文件
if(is_dir($dir_path)){
if($dir_file=opendir($dir_path)){
while(($dir_list=readdir($dir_file))!==false)
{
if($dir_list!="." && $dir_list!=".."){//如果加這裡判斷等一在顯示文件列表時.. .這樣.
echo("<div class='folder' oncontextmenu=\"return myMenuShow(this,'".$dir_path."/".$dir_list."','".$dir_path."/"."')\" id='".$dir_path."/".$dir_list."' ><a href='?url=".$dir_path."/".$dir_list."'><img src='".Getfiletype($dir_list)."' border=0 onload=\"resizepic(this);\" /></a><p id='".$dir_list."' onClick=\"edit(this,'".$dir_path."/".$dir_list."');\" >".$dir_list."</p></div>\n");
}
}
}else{
echo($dir_path."<br/>");
}
}else{
echo($dir_path."<br/>");
}
Folderexp($dir_path);
}
function Getfiletype($dir){//根據擴展名顯示相應的圖片
global $_GET;
if(@$_GET['url'] !='' and is_dir(@$_GET['url'])){
$dir = $_GET['url'].'\\'.$dir;
}
//print_r( $dir);
if($dir == '' || is_null($dir) || empty($dir)){return false;}
if(is_dir($dir)){
return 'fold.jpg';
}else{
return (Getextends($dir));
}
}
function Getextends($dir){
if($dir =="" || is_null($dir)){return "unkown.jpg";}
$Extends_name = substr($dir,strrpos($dir,".")+1);
$Extends_img = array('jpg','jpeg','gif','png','bmp','psd');
if(in_array($Extends_name,$Extends_img)){return $dir;}
switch($Extends_name){
case "php":
return 'image/asp_php_jsp.jpg';
break;
case "asp":
return 'image/asp_php_jsp.jpg';
break;
case "jsp":
return 'image/asp_php_jsp.jpg';
break;
case "aspx":
return 'image/asp_php_jsp.jpg';
break;
case "xml":
return 'image/asp_php_jsp.jpg';
break;
case "htm":
return 'image/html_js.jpg';
break;
case "html":
return 'image/html_js.jpg';
break;
case "shtml":
return 'image/html_js.jpg';
break;
case "js":
return 'image/html_js.jpg';
break;
case "txt":
return 'image/txt.jpg';
break;
case "doc":
return 'image/word.jpg';
break;
default:
return 'image/fold.jpg';
}
}
function Folderexp($dir_path){//新建文件夾
echo("<div id='t0'></div>");
echo("<div id=\"t\">");
echo("<img src=\"image/fold.jpg\" width=\"52\" height=\"50\">");
echo("<p id='t1'>");
echo("<input type=\"text\" value=\"New folder\" onblur=\"Losefocus(this,'".$dir_path."');\"; >");
echo("</p>");
echo("</div>");
}
function Tool($dir_path,$lastdir){//這裡顯示菜單條
echo("<div id=\"tool\">");
echo("<a href=\"dir.php\" class=\"ta\"><img src=\"image/tool_root.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onclick=\"history.go(-1);\" ><img src=\"image/tool_back.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onclick=\"history.go(1);\" ><img src=\"image/tool_go.gif\" border=\"0\"></a>");
echo("<a href=\"?url=$lastdir\" class=\"ta\" title='返回上級目錄'><img src=\"image/tool_s.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onclick=\"CreateText();\" title=\"新建文本文件\"><img src=\"image/tool_txt.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onClick=\"Createfolder();\" title=\"新建文件夾\" ><img src=\"image/tool_newfolder.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onclick=\"return Past('filepath','".$dir_path."')\" ><img src=\"image/tool_past.gif\" border=\"0\"></a>");
echo("<a href=\"#\" class=\"ta\" onClick=\"Upload('".$dir_path."');\" title=\"文件上傳\" ><img src=\"image/tool_upload.gif\" border=\"0\"></a>");
echo("</div>");
}
?>
<div id="Layer1" style="position:absolute; width:480px; height:20px; z-index:1; left: 293px; top: 143px;">
</div>
</body>
</html>
上一篇