<html>
<head>
<title>文件管理</title>
<meta charset='utf-8' />
</head>
<body>
<?php
//定义要查看的目录
$dir="/"; //先判断$_GET['a']是否已经传值 防止NOTICE错误
if(isset($_GET['a'])){
//选择判断要执行的操作
switch($_GET['a']){
case 'creat':
//新建文件
$filename=$_POST["filename"];
$filename=rtrim($dir,"/")."/".$filename;
//写入文件 写入一个空字符串
file_put_contents($filename,"");
break;
case 'del':
//删除文件
unlink($_GET['filename']);
break;
case 'update':
//修改文件
file_put_contents($_POST['filename'],$_POST['content']);
echo "修改成功";
header("refresh:1;url=index.php");
break;
}
} ?>
<center>
<h1>文件管理</h1>
<form action='index.php?a=creat' method='post'>
文件:<input type='text' name='filename' />
<input type='submit' value='新建' />
</form>
<table border='' width='' cellpadding='' cellspacing=''>
<tr>
<th>文件名</th>
<th>类型</th>
<th>大小</th>
<th>创建时间</th>
<th>操作</th>
</tr>
<?php
//遍历目录
$dd=opendir($dir);
while(false !== ($f=readdir($dd))){
//过滤点
if($f == "." || $f == ".."){
continue;
}
//拼路径
$file=rtrim($dir,"/")."/".$f;
//防止中文乱码
$f2=iconv("gb2312","utf-8",$f);
echo "<tr>";
echo "<td>{$f2}</td>";
echo "<td>".filetype($file)."</td>";
echo "<td>".filesize($file)."</td>";
echo "<td>".filectime($file)."</td>";
echo "<td align='center'>
<a href='index.php?a=edit&filename={$file}'>修改</a>|
<a href='index.php?a=del&filename={$file}'>删除</a>
</td>";
echo "</tr>"; }
?>
</table>
<?php
if(isset($_GET['a']) && $_GET['a']=='edit'){
echo "<hr/>";
echo "<form action='index.php?a=update' method='post'>";
echo "文件名:<input type='text' name='filename' readonly value='{$_GET['filename']}' />";
echo "<br/><br/>";
echo "<textarea name='content' rows='5' cols='30'>".file_get_contents($_GET['filename'])."</textarea>";
echo "<br/><br/>";
echo "<input type='submit' value='保存修改' />";
echo "</form>";
} ?>
</center>
</body>
</html>

php简单文件管理器——php经典实例

最新文章

  1. 从csv文件导数据到MySQL
  2. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
  3. C#使用sharppcap实现网络抓包-----2
  4. oracle学习----DDL锁理解
  5. Chrome不支持NPAPI的信息与替代方案
  6. datagrid公用字段扩展
  7. android style=&quot;@[package:]style/style_name&quot; ----------styles.xml
  8. windows phone 独立存储空间的操作 (2)
  9. SurfaceView浅析
  10. docker 学习资料收集
  11. MongoDB数据库基础
  12. django 应用中获取访问者ip地址
  13. Oracle传输表空间介绍
  14. SAS FORMAT 逻辑库存储 【输出格式 没有找到或无法加载】解决方法
  15. 获取当前操作的IFrame对象的方法
  16. IntelliJ IDEA java项目导入jar包,打jar包
  17. CH2101 可达性统计
  18. 使用es6总结笔记
  19. shell的命令格式
  20. Linux上安装Redis教程

热门文章

  1. 第139天:详解cookie、 sessionStorage 和localStorage
  2. 第109天:Ajax请求GET和POST的区别
  3. 【EF】Entity Framework Core 命名约定
  4. Luogu 4917 天守阁的地板(莫比乌斯反演+线性筛)
  5. 深入理解JVM一内存模型、可见性、指令重排序
  6. Frequent values UVA - 11235(巧妙地RMQ)
  7. hive 分区表和分桶表
  8. 【比赛】HNOI2018 转盘
  9. 【BZOJ1491】【NOI2007】社交网络(最短路,动态规划)
  10. skip-external-locking --mysql配置说明