简易上传文件管理系统

<?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" οnsubmit="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:;\" οnclick=\"window.open('" . $path . "/" . $name . "');\">下载</a></td>";
            echo "<td><a href=\"javascript:;\" οnclick=\"del('" . $name . "');\">删除</a></td>";
            echo "</tr>";
        }
    }
}
?>
</table>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值