本站所有内容仅限用于学习和研究目的,如有侵权请邮件与我们联系处理!
世上事本无难易,为之则易!

网站首页 站群教程 原创站群教程 正文

简洁高效的文件管理系统PHP源码

曹操 2022-09-27 原创站群教程 522 ℃ 1 评论 15033字 free 收藏

自用文件管理系统PHP代码,一段独立的php文件,虽然界面较为潦草,但是简单高效,可以直观的看到网站目录下的所有文件。

简洁高效的文件管理系统PHP源码-第1张图片

源代码从网上下载下来的,发现源文件的列出文件名,没有加超链接,遂给单一文件增加链接,便于快捷打开。

功能说明

1、列出目录下的文件夹和文件,以文件夹在前,文件在后的方式显示;

2、可以打开目录进入二级或N级目录;

3、可以删除文件及文件夹;

4、可以移动文件,如果指定文件夹不存在,将会被创建;

5、可以修改文件,仅包括:asp,php,html,htm,aspx,jsp;

5、可以新建文件夹;

6、可以上传文件;

BUG和不足

1、修改文件后,只能将文件保存为gb2312编码,没找到方法解决;

2、没有群移动和群删除功能;

3、没有移动文件夹功能;

4、移动文件时的目标文件夹只能自己指定,不提供选择;

文件管理源码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- 程序仅供断网状态下本地测试,请勿上传网络,请勿用于非法用途! -->
<!-- 大哥没文化,大哥也不爱说话!但是大哥爱你! by ccooc &  peace and love -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文件管理</title>
<style type="text/css">
*{font-size:12px;}
tr{height:25px;line-height:25px;background-color:#efefef;}
td{text-indent:5px;}
tr:hover{background-color:#666;color:#fff;}
tr:hover a{color:#fff;}
cite{float:right;margin-right:3px;font-style:normal;}
cite a{color:#fff;}
.trTitle{background-color:#555;font-weight:bold;color:#fff;}
.dir{background-color:#99FFCC;}
.file{background-color:#FFFFCC;}

h3{margin:0px;padding:0px;background-color:#555;color:#fff;text-indent:10px;height:25px;line-height:25px;}
h3 span{margin-left:10px;}

textarea{background-color:#f7f7f7;}

ul{list-style:none;margin:0px;padding:0px;height:50px;}
li{float:right;width:50px;height:50px;line-height:50px;text-align:center;margin-right:3px;background-color:#666;}
li a{color:#fff;text-decoration:none;display:block;width:50px;height:50px;font-weight:bold;}
li a:hover{background-color:#999;}
</style>
<script type="text/javascript">
function opendiv(action,divId)
{
if(action=="open")
{
document.getElementById(divId).style.display="block";
}
else
{
document.getElementById(divId).style.display="none";
}
}
function fillfile(urlstr,file)
{
document.getElementById('movefileurl').value=urlstr;
document.getElementById('movefilename').value=file;
//document.getElementById('testdiv').innerHTML=urlstr+"|"+file;
opendiv('open','movefileform');
}
</script>
</head>
<body>
<div style="width:600px;border:1px solid #666;">
<div style="width:100%;background-color:#555;height:50px;"><span style="float:left;font-weight:bold;font-size:14px;color:#fff;margin-left:10px;margin-top:5px;">曹操蜘蛛统计系统-文件管理 by ccooc</span>
  <ul>
    <li><a href="javascript:history.go(-1);">向上</a></li>
    <li><a href="javascript:opendiv('open','uploadform');">上传</a></li>
    <li><a href="javascript:opendiv('open','newdirform');">新目录</a></li>
    <li><a href="loaddir.php">根目录</a></li>
  </ul>
</div>
<?
//获取参数
$action=$_GET["action"];
$urlStr=$_GET["urlstr"];
$fileName=$_GET["filename"];
$file=$_GET["file"];
ini_set('date.timezone','Asia/Shanghai');

//上传表单
echo "<div style=\"display:none;width:600px;height:100px;border-bottom:1px solid #999;position:absolute;top:60px;background-color:#f7f7f7;\" id=\"uploadform\">";
echo "<h3><cite><a href=\"javascript:opendiv('close','uploadform');\">Close</a></cite><span>上传文件:</span></h3>";
echo "<div style=\"width:100%;height:75px;line-height:75px;text-align:center;\">";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"loaddir.php?action=upload&filename=$fileName\">请选择文件:<input type=\"file\" name=\"upload_file\" /> <input type=\"submit\" value=\"Upload\" /></form>";
echo "</div>";
echo "</div>";

//新建目录表单
echo "<div style=\"display:none;width:600px;height:100px;border-bottom:1px solid #999;position:absolute;top:60px;background-color:#f7f7f7;\" id=\"newdirform\">";
echo "<h3><cite><a href=\"javascript:opendiv('close','newdirform');\">Close</a></cite><span>新建目录:</span></h3>";
echo "<div style=\"width:100%;height:75px;line-height:75px;text-align:center;\">";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"loaddir.php?action=newdir&filename=$fileName\">文件夹名称:<input type=\"text\" name=\"dir_name\" style=\"width:150px;\" /> <input type=\"submit\" value=\"Add\" /></form>";
echo "</div>";
echo "</div>";

//移动文件表单
echo "<div style=\"display:none;width:600px;height:80px;border-bottom:1px solid #999;position:absolute;top:10px;background-color:#f7f7f7;\" id=\"movefileform\">";
echo "<h3><cite><a href=\"javascript:opendiv('close','movefileform');\">Close</a></cite><span>移动文件:</span></h3>";
echo "<div style=\"width:100%;height:55px;text-align:center;\">";
echo "<form method=\"post\" action=\"loaddir.php?action=move\"><p style='margin:0px;padding:0px;height:20px;line-height:20px;color:#ff0000;'>注:如果目标文件夹不存在,将会被创建。可以填目录里目录,如:test/test,结尾不能有/。</p>目标文件夹名称:<input type=\"text\" name=\"todirname\" style=\"width:150px;\" /> <input type='hidden' name='urlstr' value='' id='movefileurl' /> <input type='hidden' name='file' value='' id='movefilename' /> <input type=\"submit\" value=\"Move\" /></form>";
echo "<div id='testdiv'></div>";
echo "</div>";
echo "</div>";

//输出表格
echo "<table style=\"width:100%;\">";

//读文件夹下的文件 
function loadDir($dirName)
{
if($handle=openDir($dirName))
{
echo "<tr><td>类型</td><td>文件名</td><td>大小</td><td>最后修改时间</td><td>操作</td></tr>";
while(false!==($files=readDir($handle)))
{
if($files!="."&&$files!="..")
{
$urlStrs=$dirName."/".$files;

if(is_dir($dirName."/".$files))
{
$types="目录";
$cons="<a href=\"loaddir.php?action=open&filename=$urlStrs\">Open</a> | <a href='loaddir.php?action=del&urlstr=$urlStrs'>Del</a>";
$className="dir";
$fileaTime="";
$fileSize=getSize($dirName."/".$files);
echo "<tr class='$className'><td>$types</td><td>$files</td><td>".$fileSize." bytes</td><td>$fileaTime</td><td>$cons</td></tr>";
}
else 
{
$types="文件";
$cons="<a href=\"javascript:fillfile('$urlStrs','$files');\">Move</a> | <a href=\"loaddir.php?action=edit&urlstr=$urlStrs\">Edit</a> | <a href='loaddir.php?action=del&urlstr=$urlStrs'>Del</a>";
$className="file";
$fileSize=getSize($dirName."/".$files);
$fileaTime=date("Y-m-d H:i:s",getEditTime($dirName."/".$files));
$arrayfile[]="<tr class='$className'><td>$types</td><td><a href='$dirName/$files' target='_blank'>$files</a></td><td>".$fileSize." bytes</td><td>$fileaTime</td><td>$cons</td></tr>";
}
//echo "<tr class='$className'><td>$types</td><td>$files</td><td>".$fileSize." bytes</td><td>$fileaTime</td><td>$cons</td></tr>";
}
}
//$arraydirLen=count($arraydir);
//for($i=0;$i<$arraydirLen;$i++) echo $arraydir[$i];
$arrayfileLen=count($arrayfile);
for($i=0;$i<$arrayfileLen;$i++) echo $arrayfile[$i];
//echo $arraydir;
closeDir($handle);
}
}

//删除文件
function killFile($filename)
{
if(file_exists($filename))
{
if(!is_dir($filename))
{
unlink($filename);
echo "成功删除文件:".$filename;
}
else 
{
rmDir($filename);
echo "成功删除目录:".$filename;
}
}
else 
{
echo "指定文件或文件夹不存在";
}
//echo "可不能想删就删啊";
}

//获取文件大小
function getSize($a)
{
if(file_exists($a))
{
return fileSize($a);
}
}

//获取最后修改时间
function getEditTime($a)
{
if(file_exists($a))
{
return filemTime($a);
}
}

//读取文件
function readFiles($a)
{
//$exts=substr($a,-3);
$exts=explode(".",$a);
$extsNums=count($exts);
$exts=$exts[$extsNums-1];
if($exts=="php"||$exts=="asp"||$exts=="txt"||$exts=="html"||$exts=="aspx"||$exts=="jsp"||$exts=="htm")
{
$handle=@fOpen($a,"r");
if($handle)
{
echo "<h3>修改文件:$a</h3>";
echo "<form action='loaddir.php?action=doedit&urlstr=$a' method='post'><textarea style='width:99%;height:300px;margin-left:auto;margin-right:auto;' name='content'>";
while(!fEof($handle))
{
//$buffer=fGets($handle);
//echo ubb(mb_convert_variables(fGets($handle),"gb2312","gb2312,utf-8"));
echo ubb(mb_convert_encoding(fGets($handle),"gb2312","utf-8,gb2312"));
//echo ubb(iconv("utf-8,gb2312","gb2312",fGets($handle)));
//echo ubb(fGets($handle));
}
fClose($handle);
echo "</textarea><h3><input type='submit' value='Edit' /></h3></form>";
}
else 
{
echo "文件不存在或不可用";
}
}
else 
{
echo "不能编辑该文件";
}
}

//修改文件
function editFiles($a)
{
$contents=get_magic_quotes_gpc()?stripslashes($_POST["content"]):$_POST["content"];
//if(get_magic_quotes_gpc()) $contents=stripslashes($_POST["content"]); else $contents=$_POST["content"];

if(is_writeable($a))
{
//echo substr(sprintf('%o',fileperms($a)),-4);
if(!$handle=@fopen($a,"wb"))
{
echo "不能打开文件:$a";
exit;
}
if(@fwrite($handle,$contents)===FALSE)
{
echo "不能写入到文件:$a";
}
else 
{
echo "修改文件成功";
}
@fclose($handle);
}
else 
{
echo "不能修改文件";
}
/*if(function_exists("file_put_contents"))
{
if(file_put_contents($a,$contents))
{
echo "修改文件成功";
}
else 
{
echo "修改文件失败";
}
}
else 
{
echo "貌似不能使用修改功能";
}*/
}

//字符转换
function ubb($str)
{
$str=str_replace("<","&lt;",$str);
$str=str_replace(">","&gt;",$str);
return $str;
}

//上传处理
function upLoadFile($a)
{
if(is_dir($a)||$a==""||$a==".")
{
if($_FILES)
{
$dest=$a?$a."/":$a;
$file_name=$dest.$_FILES['upload_file']['name'];
//echo $file_name;
if(move_uploaded_file($_FILES['upload_file']['tmp_name'],$file_name))
{
echo "上传成功";
}
else 
{
echo "上传失败";
}
}
}
else 
{
echo "所在路径不是一个目录,不能上传";
}
//echo "可不能想传就传";
}

//新建目录
function newDir($a)
{
if(is_dir($a)||$a==""||$a==".")
{
$dest=$a?$a."/":$a;
$dirName=$_POST['dir_name'];
if(mkdir($dest.$dirName))
{
echo "创建目录成功";
}
else 
{
echo "创建目录失败";
}
}
else 
{
echo "所在路径不是一个目录,不能创建目录";
}
//echo "可不能想建就建";
}

//移动文件
function moveFile()
{
$todirname=$_POST['todirname'];
$fileurlstr=$_POST['urlstr'];
$file=$_POST['file'];
//echo $todirname."<br/>";
//echo $fileurlstr."<br/>";
//echo $file."<br/>";
if(!is_dir($todirname))
{
mkdir($todirname);
}
if(!is_dir($fileurlstr))
{
if(rename($fileurlstr,$todirname."/".$file))
{
echo "移动文件成功";
}
else 
{
echo "移动文件失败";
}
}
//echo "可不能想移就移";
}

//具体操作
if(!$action)
{
loadDir(".");
}
elseIf($action=="del")
{
killFile($urlStr);
}
elseIf ($action=="edit")
{
readFiles($urlStr);
}
elseif ($action=="doedit")
{
editFiles($urlStr);
}
elseif($action=="upload")
{
upLoadFile($fileName);
}
elseif($action=="newdir")
{
newDir($fileName);
}
elseif($action=="move")
{
moveFile();
}
else
{
loadDir($fileName);
}
?>
</table>
</div>
</body>
</html>

由于转载BOY太多了,所以页面设置了禁止直接复制。

有需要的朋友可以联系站长逐一发送,也可以搜索部分关键词在网上自行寻找相同的版本。

我们的区别不过是修改了第125行的代码,增加了超链接而已。

$arrayfile[]="<tr class='$className'><td>$types</td><td><a href='$dirName/$files' target='_blank'>$files</a></td><td>".$fileSize." bytes</td><td>$fileaTime</td><td>$cons</td></tr>";

下载链接

视频教程素材来源于网络,仅供测试下载速度,请下载后立刻删除!

隐藏内容
评论可见
前往评论

目录导航
  • 功能说明
  • BUG和不足
  • 文件管理源码
  • 下载链接

  • Tags:蜘蛛统计曹操蜘蛛

    必看说明

    • 本站中所有被研究的素材与信息全部来源于互联网,版权争议与本站无关。
    • 本站文章或仅为文本内容原创,非程序原创。如有侵权、不妥之处,请联系站长第一时间删除。敬请谅解!
    • 本站所有内容严格遵守国家法律的条例,所有研究的算法技术均来源于搜索引擎公开默认允许用户研究使用的接口。
    • 阅读本文及获取资源前,请确保您已充分阅读并理解《访问曹操SEO网站需知:行为准则》。
    • 本站分享的任何工具、程序仅供学习参考编写架构,仅可在本地的虚拟机内断网测试,严禁联网运行或上传搭建!
    • 任何资源必须在下载后24个小时内,从电脑中彻底删除。不得传播或者用于其他任何用途!否则一切后果用户自负!
    • 转载请注明 : 文章转载自  曹操SEO 简洁高效的文件管理系统PHP源码
    • 本文标题:《简洁高效的文件管理系统PHP源码》
    • 本文链接:https://www.ccooc.cn/1788.html

    已有1位网友发表了看法:

    • 97604696

      97604696  评论于 [2022-09-27 16:06:43]  回复

      下载个看看

    欢迎 发表评论:

    网站分类
    近期评论
    文章归档
    标签列表
    站点信息
    • 文章总数:2021
    • 页面总数:7
    • 分类总数:46
    • 标签总数:340
    • 评论总数:8891
    • 浏览总数:5165013