首页 > 编程 > PHP > 正文

php_web文件管理系统_day01

2019-11-08 00:52:32
字体:
来源:转载
供稿:网友

效果图

这里写图片描述

文件遍历

<?php //打开指定目录/** * 遍历目录函数,只读取目录中的最外层的内容 * @param string $path * @return array */function readDirectory($path) { $handle = opendir ( $path ); while ( ($item = readdir ( $handle )) !== false ) { //.和..这2个特殊目录 if ($item != "." && $item != "..") { if (is_file ( $path . "/" . $item )) { $arr ['file'] [] = $item; } if (is_dir ( $path . "/" . $item )) { $arr ['dir'] [] = $item; } } } closedir ( $handle ); return $arr;}

转换字节大小

<?php //Bytes/Kb/Mb/Gb/Tb/Eb/** * 转换字节大小 * @param number $size * @return float */function transBytes($size) { $arr = array("Byte", "KB", "MB", "GB", "TB", "EB"); $i = 0; while($size >= 1024) { $size /= 1024; $i++; } return round($size,2).$arr[$i];}?>

index.php

<?php require_once 'dir.func.php';require_once 'file.func.php';$path="file";$info=readDirectory($path);//PRint_r($info)?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Insert title here</title><link rel="stylesheet" href="cikonss.CSS" /><script src="jquery-ui/js/jquery-1.10.2.js"></script><script src="jquery-ui/js/jquery-ui-1.10.4.custom.js"></script><script src="jquery-ui/js/jquery-ui-1.10.4.custom.min.js"></script><link rel="stylesheet" href="jquery-ui/css/ui-lightness/jquery-ui-1.10.4.custom.css" type="text/css"/><style type="text/css"> body,p,div,ul,ol,table,dl,dd,dt{ margin:0; padding: 0; } a{ text-decoration: none; } ul,li{ list-style: none; float: left; } #top{ width:100%; height:48px; margin:0 auto; background: #E2E2E2; } #navi a{ display: block; width:48px; height: 48px; } #main{ margin:0 auto; border:2px solid #ABCDEF; } .small{ width:25px; height:25px; border:0;}</style><script type="text/javascript"></script></head><body><div id="showDetail" style="display:none"><img src="" id="showImg" alt=""/></div><h1>在线文件管理器</h1><div id="top"> <ul id="navi"> <li><a href="index.php" title="主目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-home"></span></span></a></li> <li><a href="#" onclick="" title="新建文件" ><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-file"></span></span></a></li> <li><a href="#" onclick="" title="新建文件夹"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-folder"></span></span></a></li> <li><a href="#" onclick=""title="上传文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-upload"></span></span></a></li> <li><a href="#" title="返回上级目录" onclick=""><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-arrowLeft"></span></span></a></li> </ul></div><form action="index.php" method="post" enctype="multipart/form-data"><table width="100%" border="1" cellpadding="5" cellspacing="0" bgcolor="#ABCDEF" align="center"> <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> // 核心代码start <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;?>"></img></td> <td><?php echo transBytes(filesize($p))?></td> <td><?php $src = is_readable($p)?"correct.png":"error.png"?><img src="images/<?php echo $src;?>" title="可读" height="50px" width="50px"/></td> <td><?php $src = is_writable($p)?"correct.png":"error.png"?><img src="images/<?php echo $src;?>" title="可写" height="50px" width="50px"/></td> <td><?php $src = is_executable($p)?"correct.png":"error.png"?><img src="images/<?php echo $src;?>" title="可执行" height="50px" width="50px"/></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> // 核心代码end <td> <a href="index.php?act=showContent&path=&filename=" ><img class="small" src="images/show.png" alt="" title="查看"/></a>| <a href="index.php?act=editContent&path="><img class="small" src="images/edit.png" alt="" title="修改"/></a>| <a href="index.php?act=renameFile&path=&filename="><img class="small" src="images/rename.png" alt="" title="重命名"/></a>| <a href="index.php?act=copyFile&path=&filename="><img class="small" src="images/copy.png" alt="" title="复制"/></a>| <a href="index.php?act=cutFile&path=&filename="><img class="small" src="images/cut.png" alt="" title="剪切"/></a>| <a href="#" onclick="')"><img class="small" src="images/delete.png" alt="" title="删除"/></a>| <a href="index.php?act=downFile&path=&filename="><img class="small" src="images/download.png" alt="" title="下载"/></a> </td> </tr> <?php $i++; } } ?></table></form></body></html>
上一篇:PHP学习一

下一篇:PHP的日期和时间

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表