<?php
require_once 'dir.func.php';
require_once 'file.func.php';
require_once 'common.func.php';
$path = "file";
$act = $_REQUEST['act'];
$filename = $_REQUEST['filename'];
$info = readDirectory($path);
// print_r($info);
$redirect = "index.php?path={$path}";
if ($act == "createFile") {
// 创建文件 查看文件 修改文件
// echo $path;
// echo $filename;
$mes = createFile($path . "/" . $filename);
alertMes($mes, $redirect);
} else if ($act == "showContent") {
// 查看文件内容
$content = file_get_contents($filename);
// cho "<textarea readonly='raedonly' clos='100' rows='20'>$c</textarea>" ;
// 高亮显示PHP代码
if (strlen($content)) {
// 高亮显示字符串中的PHP代码
$newContent = highlight_string($content, true);
// 高亮显示文件中的PHP代码
// highlight_file($filename);
$str = <<<XGG
<table width="100%" height="10%" bgcolor="pink">
<tr><td>{$newContent}</td></tr>
</table>
XGG;
echo $str;
} else {
alertMes("这个文件没有内容,请编辑再查看!", "$redirect");
}
}else if($act=='editContent'){
//修改文件内容
//echo "编辑文件";
//得到文件内容
$content=file_get_contents($filename);
$str=<<<XGG
<form action='index.php?act=doEdit' method='post'>
<textarea name='content' cols='190' rows='10' >{$content}</textarea><br/>
<input type='hidden' name='filename' value='{$filename}' />
<input type="submit" value="修改文件内容" />
</form>
XGG;
echo $str;
}else if ($act=="doEdit"){
//修改文件内容的操作
$content=$_REQUEST['content'];
if(file_put_contents($filename,$content)){
$mes="文件修改成功";
}else {
$mes="文件修改失败";
}
alertMes($mes, $redirect);
}
?>
<!DOCTYPE html >
<html>
<meta http-equiv="Content-Type" content="text/html" charset="GB2312">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="style.css"></link>
<--从官网下载到本地的文件加载的-->
<script type="text/javascript" src="jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script type="text/javascript" src="jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script type="text/javascript" src="jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
</head>
<body>
<h1>在线文件管理器</h1>
<div>
<ul>
<li><a href="index.php" title="主目录"><span style="margin-left: 8px, margin-top:0px"></span><img alt="" src="images/zhuye.png" /></a></li>
<li><a href="#" onclick="show('createFile')" title="新建文件"><span style="margin-left: 5px;"></span><img alt="" src="images/xinjianwenjian.png" /></a></li>
<li><a href="#" onclick="show('createFolder')" title="新建文件夹"><span style="margin-left: 5px;"></span><img alt="" src="images/xinjianwenjianjia.png" /></a></li>
<li><a href="#" onclick="show('uploadFile')" title="上传文件"><span style="margin-left: 5px;"></span><img alt="" src="images/shangchuan.png" /></a></li>
<li><a href="#" title="返回上级目录" onclick="back('<?php //echo $back;?>')"><span style="margin-left: 5px;"></span><img alt="" src="images/fanhui.png" /></a></li>
</ul>
</div>
<script type="text/javascript">
function show(dis){
document.getElementById(dis).style.display="block";
}
function delFile(path,filename){
if(window.confirm("删除之后无法恢复,您确定要删除吗?")){
location.href="index.pnp?act=delFile&path="+path+"&filename="+filename;
}
}
function showDetail(t,filename){
$("showImg").attr("src",filename);
$("showDetail").dialog({
height:"auto",
width:"auto",
position:{my:"center",at:"center",collision:"fit"},
modal:false,//是否模式对话框
draggable:true,//是否允许拖拽
resizable:true,//是否允许拖动
title:t,//对话框标题
show:"slide",
hide:"explode"
});
}
</script>
<form action="index.php" method="post">
<table>
<tr id="createFile" style="display: none">
<td>请输入文件名称</td>
<td><input type="text" name="filename" /> <input type="hidden" name="path" value="<?php echo $path?>" /> <input type="hidden"
name="act" value="createFile" /> <input type="submit" value="创建文件" />
</td>
</tr>
<tr id="createFolder" style="display: none">
<td>请输入文件夹名称</td>
<td><input type="text" name="dirname" /> <input type="submit" name="act" value="创建文件夹" /></td>
</tr>
<tr id="uploadFile" style="display: none">
<td>请选择要上传的文件</td>
<td><input type="file" name="filename" /> <input type="submit" name="act" value="上传文件" /></td>
</tr>
<tr>
<td>编号</td>
<td>名称</td>
<td>类型</td>
<td>大小</td>
<td>可读</td>
<td>可写</td>
<td>可执行</td>
<td>创建时间</td>
<td>修改时间</td>
<td>访问时间</td>
<td>操作</td>
</tr>
<?php
if ($info ['file']) {
$i = 1;
foreach ($info ['file'] as $val) {
$p = $path . "/" . $val;
?>
<tr>
<td><?php echo $i;?> </td>
<td><?php echo $val;?></td>
<td><?php $src=filetype($p)=="file"?"file_ico.png":"folder_ico.png";?><img
src="images/<?php echo $src ?>" alt=" " title="文件" /></td>
<td><?php echo transByte(filesize("$p"))?></td>
<td><?php $src=is_readable($p)?"correct.png":"error.png";?><img
src="images/<?php echo $src; ?>" alt=" " /></td>
<td><?php $src=is_writable($p)?"correct.png":"error.png";?><img
src="images/<?php echo $src; ?>" alt=" " /></td>
<td><?php $src=is_executable($p)?"correct.png":"error.png";?><img
src="images/<?php echo $src; ?>" alt=" " /></td>
<td><?php echo date("Y-m-d H:i:s",filectime($p));?></td>
<td><?php echo date("Y-m-d H:i:s",filemtime($p));?></td>
<td><?php echo date("Y-m-d H:i:s",fileatime($p));?></td>
<td>
<?php
$tmp_name=explode(".", $val);
$ext = strtolower(end($tmp_name));
$imageExt = array(
"gif",
"jpg",
"jpeg",
"png"
);
if (in_array($ext, $imageExt)) {
?>
<a href="#"
onclick="showDetail('<?php echo $val;?>','<?php echo $p;?>')"><img
alt="" src="images/show.png" title="查看" /></a>
<?php
} else {
?>
<a href="index.php?act=showContent&filename=<?php echo $p;?>"><img
alt="" src="images/show.png" title="查看" /></a>
<?php }?>
<a href="index.php?act=editContent&filename=<?php echo $p;?>"><img
alt="" src="images/edit.png" title="修改" /></a> <a
href="index.php?act=renameFile&path=<?php echo $p;?>"><img alt=""
src="images/rename.png" title="重命名" /></a> <a
href="index.php?act=copyFile&path=<?php echo $p;?>"><img alt=""
src="images/copy.png" title="复制" /></a> <a
href="index.php?act=moveFile&path=<?php echo $p;?>"><img alt=""
src="images/cut.png" title="剪切" /></a> <a href="#"
onclick="delFile('<?php echo $p;?>','<?php echo $p.'/'.$val;?>')"><img
alt="" src="images/delete.png" title="删除" /></a> <a
href="index.php?act=downFile&path=<?php echo $p;?>&filename<?php echo $p.'/'.$val;?>"><img
alt="" src="images/download.png" title="下载" /></a>
</td>
</tr>
<?php
$i ++;
}
}
?>
</table>
</form>
</body>
</html>
少写了这个代码,用来显示图片的框:<div id="showDetail" style="display:none"><img src="" id="showImg" alt=""/></div>