分享
 
 
 

简易文件管理系统

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

我学习PHP做的第一个程序是文件管理,现在拿出来给大家,有什么缺点请指出来,这样有利于大家的学习和进步。也希望能对新手有所帮助。

index.php

<?php

if(isset($_GET['path']) && strlen(trim($_GET['path']))!=0){

$dir = $_GET['path'];

}else{

$dir = "/";

}

$pageSize = 20; //

$pageNum = 1; //

$pageTitle = 1; //

$fileTitle = 0; //

$folderTitle = 0; //

$currFileNum = 0; //

$currFolerNum = 0; //

if(isset($_GET['pagenum']))$pageNum = $_GET['pagenum'];

if($pageNum<1)$pageNum=1;

//echo $pageNum;

?>

<html>

<head>

<title>File Administrator System</title>

<script language="javascript">

<!--

function ReName(dir,filename){

var newName;

//return false;

newName = prompt("Input the new name( include the suffix, such as\".Htm\".)", filename);

if(newName == null)return false;

if(newName.length<4){

alert("The document is illegal, pleasing input afresh!!!");

return false;

}

var cmd = "cmd.php?cmd=rename&old="+dir+filename+"&new="+dir+newName;

var WinId=window.open(cmd, 'popUpWin', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width=200,height=200");

if (WinId && WinId.open && !WinId.close){

return false;

}else{

//WinId.close();

location.reload();

}

}

function Del(cmd,dir){

var cmd = "cmd.php?cmd="+cmd+"&dir="+dir;

//alert(cmd);

var WinId=window.open(cmd, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width=200,height=200');

if (WinId && WinId.open && !WinId.close){

return false;

}else{

//WinId.close();

location.reload();

}

}

function checkform(){

var strPath = new String(document.upfileform.upfile.value);

if(strPath.length < 5){

alert("First, choose the top that want the document spread, then click the top spreads!!!");

document.upfileform.upfile.focus();

return false;

}else{

var fileName;

fileName = prompt("Top that input document after spreading, include the suffix, such as'.Htm', if the document is by name empty, then will ascend to spread by the source document."," ");

document.upfileform.up.value = fileName;

document.upfileform.action = "up.php";

document.upfileform.submit();

}//end if

}

function newFolder(dir)

{

var newName;

newName = prompt("Input the document that to establish clip the name!!!","newFolder");

if(newName == null)return false;

var cmd = "cmd.php?cmd=mkdir&dir=" + dir + newName;

var WinId = window.open(cmd, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width=200,height=200');

if (WinId && WinId.open && !WinId.close){

pa = "<div>Builder folder defeated.</div>"

WinId.document.write("");

WinId.document.close();

WinId.document.write(pa);

}else{

//WinId.close();

location.reload();

}

}

function downFile(filePath)

{

WinId = window.open("downFile.php?path="+filePath);

}

//-->

</script>

<style type="text/css">

body {

margin-left: 0px;

margin-top: 5px;

margin-right: 0px;

margin-bottom: 0px;

}

A:link {

TEXT-DECORATION: none;

color: #000000;

}

A:visited {

COLOR: #999999;

TEXT-DECORATION: none

}

A:active {

COLOR: #CCCCCC;

TEXT-DECORATION: none

}

A:hover {

COLOR: #696969;

TEXT-DECORATION: none

}

.tab {

border-top-width: 1px;

border-right-width: 1px;

border-bottom-width: 1px;

border-left-width: 1px;

border-top-style: dashed;

border-right-style: dashed;

border-bottom-style: dashed;

border-left-style: dashed;

border-top-color: #CCCCCC;

border-right-color: #666666;

border-bottom-color: #666666;

border-left-color: #CCCCCC;

font-size: 12px;

font-weight: normal;

color: #000000;

text-decoration: none;

padding-top: 1px;

padding-right: 1px;

padding-bottom: 1px;

padding-left: 1px;

}

.txt {

font-size: 12px;

font-weight: normal;

color: #000000;

text-decoration: none;

}

.style1 {

font-family: Geneva, Arial, Helvetica, sans-serif;

font-weight: bold;

font-size: 18px;

}

</style>

</head>

<body class="txt">

<center>

<span class="style1">File Administrator System

</span>

<table width="770" border="0" cellpadding="3" cellspacing="1" bgcolor="#0099CC">

<tr>

<td><b><font color="#FFFFFF"><?php echo dirname($dir);?></font></td>

</tr>

<tr>

<td height="78" align="center" bgcolor="#eeffff" class="txt">

<table width="740" border="0" cellpadding="1" cellspacing="1" background="ba.gif">

<tr align="center" bgcolor="#FFFFdd" class="txt">

<td width="15"></td>

<td><b>File Name</b></td>

<td width="30"><b>Type</b></td>

<td width="60"><b>Size</b></td>

<td width="160"><b>Edit Time</b></td>

<td colspan="3"><b>Option</b></td>

</tr>

<?php

$rowcolor=1;

//echo "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']). "/" ;

if ($handle = @opendir($dir)) {

while (false !== ($file = @readdir($handle))) {

if(@filetype($dir.$file)=="file"){

$currfileNum++;

}else{

$currfolderNum++;

}

if (($currfileNum+$currfolderNum)<=$pageNum*$pageSize && ($currfileNum+$currfolderNum)>($pageNum-1)*$pageSize) { //

$rowcolor+=1; //

if($rowcolor%2)

$color="#FFE4E1";

else

$color="#ffffff";

?>

<tr bgcolor=<?php echo $color;?> class="txt">

<td align="right"><?php echo $currfileNum + $currfolderNum;?><img src="RedArrow.gif" width="4" height="7"></td>

<td><?php

if(substr($dir,-1)!="/" && substr($dir,-2)!=".." && substr($dir,-1)!="." && substr($dir,-1)!="\")$dir.="/";

if($file=="."){

if(substr($dir,-1)=="/")$dirTemp = substr($dir,0,strlen($dir)-1);

$dirTemp = substr($dirTemp,0,strrpos($dirTemp,"/"));

if($dirTemp=="")$dirTemp="/";

echo "<a href=index.php?path=".urlencode($dirTemp)." title='Click Up Folder'><font color=#696933>";

}elseif($file==".."){

echo "<a href=index.php?path=".urlencode($dir)." title='Click Reload'><font color=#696933>";

}elseif(filetype($dir.$file)=="file"){

?><div onclick='downFile("<?php echo $dir.$file ;?>")' style="cursor:hand" title="Click Down File"><?php

}else{

$fire.="/";

echo "<a href=index.php?path=".urlencode($dir).urlencode($file)." title='Click Into'><font color=#000000>";

}echo $file."</font></a>";

//echo "&nbsp;&nbsp;&nbsp;".filetype($dir.$file)."</td>";

echo "</td><td align=right>";

echo @filetype($dir.$file);

echo "</td>";

$temp = @filesize($dir.$file);

$Fs ="b";

if($temp<800) {

$Fs ="b";

//echo $temp."b<br>";

}else{

$temp = $temp/1024;

if($temp<600) {

$Fs ="Kb";

//echo $temp."Kb<br>";

}else{

$temp = $temp/1024;

if($temp<600) {

$Fs ="Mb";

//echo $temp."Mb<br>";

}else{

$temp = $temp/1024;

if($temp<600) {

$Fs ="Gb";

//echo $temp."Gb<br>";

}//end if

}//end if

}//end if

}//end if

if(filetype($dir.$file)=="file")$ot = sprintf("%0.2f",$temp).$Fs;

?>

<td align="right"><?php echo $ot;$ot=Null;?></td>

<td align="center"><?php echo date ("Y-m-d H:i:s",@filectime($dir.$file));?></td>

<td align=center width="35"><div onclick='Del("<?php echo filetype($dir.$file)=="file"?"del":"rmdir" ;?>","<?php echo $dir.$file ;?>")' style="cursor:hand">Kill</div></td>

<td align=center width="35"><div onclick='ReName("<?php echo $dir ;?>","<?php echo $file ;?>")' style="cursor:hand">ReName</div></td>

<td align=center width="35"><?php if(filetype($dir.$file)=="file"){?><div onclick='downFile("<?php echo $dir.$file ;?>")' style="cursor:hand" title="Click Down File">Load</div><?php }?></td>

</tr>

<?php

}//end if

}//end while

$pageTitle = ceil(($currfileNum + $currfolderNum)/$pageSize);

}else{

echo "<center><font color=red>error: not the folder.</font></center>";

exit();

}//end if (opendir)

?>

<form name="upfileform" enctype="multipart/form-data" method="post" target="_blank">

<tr bgcolor=#ffffdd class="txt">

<td align="right"></td>

<td align="center">

<input name="upfile" type="file" class="tab" id="upfile" style="background-color:#fffafa ;font-size:12px ;height:18" size="46">

<input type="hidden" name="up" id="up" value="up">

<input type="hidden" name="dir" id="dir" value="<?php echo $dir ;?>">

<td align="center">

<input type="button" class="tab" style="background-color:#fffafa ;cursor:hand;font-size:12px ;height:18" onClick="checkform()" value="Up File">

</td>

<td align="center">

<div class="tab" style="background-color:#fffafa ;font-size:12px ;height:18;width:48;text-align:center;cursor:hand" onClick="location.reload()">Reload</div>

</td>

<td align="center"><div style="background-color:fffafa ;cursor:hand;text-align:center;height:18;width:120" class="tab"><?php echo date("Y-m-d H:i:s");?></div></td>

<td colspan="3" align=center>

<div onClick='newFolder("<?php echo $dir ;?>")' style="background-color:#fffafa ;cursor:hand;font-size:12px ;height:18;width:80" class="tab">New Folder</div>

</td>

</tr>

</form>

</table>

<?php echo $currfileNum;?>File<b> /\ </b>

<?php echo $currfolderNum;?>Folder<b> /\ </b>

<?php echo $pageTitle;?>Page<b> /\ </b>

<?php echo $pageSize;?>/page<b> /\ </b>

<?php if($pageNum>1){?>

<a href="index.php?path=<?php echo $dir;?>&pagenum=1">First</a><b>/\</b>

<a href="index.php?path=<?php echo $dir;?>&pagenum=<?php echo $pageNum-1;?>">Prev</a><b> /\ </b>

<?php }else{?>

First<b> /\ </b>

Prev<b> /\ </b>

<?php }if($pageNum<$pageTitle){?>

<a href="index.php?path=<?php echo $dir;?>&pagenum=<?php echo $pageNum+1;?>">Next</a><b> /\ </b>

<a href="index.php?path=<?php echo $dir;?>&pagenum=<?php echo $pageTitle;?>">End</a>

<?php }else{?>

Next<b> /\ </b>

End

<?php }?>

</td>

</tr>

</table>

No Copyright; Spreed freedom; Cherish the labor; People Long Live

</center>

</body>

</html>

cmd.php

<?php

if(isset($_GET['cmd'])){

if($_GET['cmd'] == "copy"){

$source = $_GET['from'];

$dest = $_GET['to'];

if(copy($source, $dest)){

echo "Copy file scceed!!!";

}else{

echo "Copy file defeated!!!";

}

}

if($_GET['cmd'] == "del"){

$dir = $_GET['dir'];

if(unlink($dir)){

echo "Delete scceed.file:\"".$dir."\"";

}else{

echo "Delete file defeated!!!";

}

}

if($_GET['cmd'] == "stat"){

$dir = $_GET['dir'];

if($arr=stat($dir)){

echo "<pre>";

echo print_r($arr);

echo "</pre>";

}else{

echo " No the Folder!!!";

}

}

if($_GET['cmd'] == "mkdir"){

$dir = $_GET['dir'];

$mode = $_GET['mode'];

if(@mkdir($dir)){

echo "Scceed builded folder:\"".$dir."\"";

}else{

echo "Defeated builded folder";

}

}

if($_GET['cmd'] == "file"){

$dir = $_GET['dir'];

if(arr=@file($dir]$arr=@file($dir)){

echo "<pre>";

echo print_r($arr);

echo "</pre>";

}else{

echo "No the File!!!";

}

}

if($_GET['cmd'] == "rename"){

$old = $_GET['old'];

$new = $_GET['new'];

if(rename($old,$new)){

echo "Scceed Run,old name:\"".$old."\",rename:\"".$new."\"";

}else{

echo "Defeated!!!";

}

}

if($_GET['cmd'] == "rmdir"){

$dir = $_GET['dir'];

if(rmdir($dir)){

echo "Scceed Run,\"".$dir."\"deleted.";

}else{

echo "Defeated";

}

}

}

?>

downFile.php

<?php

if(isset($_GET['path'])){

$path = ($_GET['path']);

if(file_exists(temp)){

//echo "Here is a folder:temp.<br>";

}else{

echo "Here is not foler:temp<br>";

mkdir(temp);

echo (file_exists(temp))?"Scceed builder new folder \"temp\".<br>":"Defeated builder new folder<br>";

}//end if

if ($handle = opendir("temp")) {

echo "hand<br>";

while (false !== ($file = @readdir($handle))) {//Scan folder "temp"

if(file_exists("temp/".$file) && trim($file)!="." && trim($file)!=".."){ //Judge whether document exsits or not

if(date("d",@filectime("temp/".$file))!=date("d") || date("H",@filectime("temp/".$file))!=date("H") || date("i",@filectime("temp/".$file))-date("i")>10){ //

unlink("temp/".$file);

echo $file."<br>Date";

echo date("d",@filectime("temp/".$file))."/";

echo date("d")."<br>Hour";

echo date("H",@filectime("temp/".$file))."/";

echo date("H")."<br>Minute";

echo date("i",@filectime("temp/".$file))."/";

echo date("i")."<br>";

}//end if

}//end if

}//end while

}//end if

$fileName = (substr($path,strrpos($path,"/")+1,strlen($path)));

$dot = substr($fileName,-4);

if($dot!=".zip" && $dot!=".rar" && $dot!=".exe" && $dot!=".chm" && $dot!=".com")$fileName .=".zip";

$copyOK = copy($path,"temp/".$fileName);

if($copyOK){

$url = "http://" . $_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF'])."/temp/".$fileName;

echo ($url);

header("location:".$url);

}else{

echo ("Server headles data mistake.");

}//end if

}

//echo "<br>http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']). "/" ;

?>

up.php

<?php

if(isset($_POST['up'])){

$name = trim($_POST['up']);

$uploaddir = $_POST['dir'];

if(substr($uploaddir,-1) != "/") $uploaddir.="/";

if($name == "") $name= $_FILES['upfile']['name'];

$uploadfile = $uploaddir.$name;

echo $uploadfile;

echo "<br>".$_FILES['upfile']['tmp_name'];

print "<pre>";

if (@move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {

print "Up file scceed!!!\n";

print_r($_FILES);

print "<script language=javascript>alert('Up file succeed.Breaking the page document would show.');</script>";

echo $uploadfile;

print "<script language=javascript>window.close();</script>";

} else {

print "<br>Up file defeated!!\n";

print_r($_FILES);

}

print "</pre>";

}

?>

main.css

.tab {

border-top-width: 1px;

border-right-width: 1px;

border-bottom-width: 1px;

border-left-width: 1px;

border-top-style: dashed;

border-right-style: dashed;

border-bottom-style: dashed;

border-left-style: dashed;

border-top-color: #CCCCCC;

border-right-color: #666666;

border-bottom-color: #666666;

border-left-color: #CCCCCC;

font-size: 12px;

font-weight: normal;

color: #000000;

text-decoration: none;

padding-top: 1px;

padding-right: 1px;

padding-bottom: 1px;

padding-left: 1px;

}

.txt {

font-size: 12px;

font-weight: normal;

color: #000000;

text-decoration: none;

}

A:link {

FONT-WEIGHT: COLOR: #000000; TEXT-DECORATION: none

}

A:visited {

FONT-WEIGHT: COLOR: #ff00ff; TEXT-DECORATION: none

}

A:active {

FONT-WEIGHT: COLOR: #00ccff; TEXT-DECORATION: none

}

A:hover {

FONT-WEIGHT: COLOR: #696969; TEXT-DECORATION: none

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有