简易上传文件管理系统
2016-07-12 14:41
477 查看
<?php if (isset($_GET['type'])) { $path = "attachment/" . date("Ymd"); if ($_GET['type'] == "0") { if (!file_exists($path)) { mkdir($path); } if (substr($_FILES["file"]["name"], -4, 4) == ".php") { echo "<span style=\"color:red\">上传失败!</span> <a href=\"index.php\">返回</a>"; } else { if (move_uploaded_file($_FILES["file"]["tmp_name"], $path . "/" . iconv("UTF-8", "GBK//IGNORE", $_FILES["file"]["name"]))) { echo "<span style=\"color:red\">上传成功!</span> <a href=\"index.php\">返回</a>"; } else { echo "<span style=\"color:red\">上传失败!</span> <a href=\"index.php\">返回</a>"; } } } else { if (unlink($path . "/" . iconv("UTF-8", "GBK//IGNORE", $_GET["filename"]))) { echo "<span style=\"color:red\">删除成功!</span> <a href=\"index.php\">返回</a>"; } else { echo "<span style=\"color:red\">删除失败!</span> <a href=\"index.php\">返回</a>"; } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>上传文件管理</title> <style type="text/css"> a{ color:#000; text-decoration:none; } </style> <script type="text/javascript"> function check(form) { if (form.file.value == "") { alert("请选择文件!"); return false; } return true; } function del(filename) { if (confirm("确认要删除 " + filename + " 吗?")) { window.location.href = "?type=1&filename=" + filename; } } </script> </head> <body> <form action="?type=0" method="post" enctype="multipart/form-data" name="form1" onsubmit="return check(this);"> <label for="file"></label> <input type="file" name="file" id="file" style="width:348px;height:24px"> <input type="submit" name="button" id="button" value="上传"> </form> <br /> <table width="400" border="1" cellpadding="0" cellspacing="0" style="text-align:center"> <tr> <td width="70%">文件名</td> <td colspan="2">操作</td> </tr> <?php $path = "attachment/" . date("Ymd"); if (file_exists($path)) { $filenames = scandir($path); foreach ($filenames as $filename) { if ($filename != "." && $filename != "..") { $name = iconv("GBK", "UTF-8", $filename); echo "<tr>"; echo "<td style=\"text-align:left\">" . $name . "</td>"; echo "<td><a href=\"javascript:;\" onclick=\"window.open('" . $path . "/" . $name . "');\">下载</a></td>"; echo "<td><a href=\"javascript:;\" onclick=\"del('" . $name . "');\">删除</a></td>"; echo "</tr>"; } } } ?> </table> </body> </html>
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- rem : web app适配的秘密武器
- jquery高级应用之Deferred对象
- 关于浮动与清除浮动,你应该知道的
- 数组reduce方法的高级技巧
- php7 读取php.ini[4]
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站