<?php header ( "Content-Type:text/html;charset=utf-8" );
if (PHP_OS === "Linux") {
define ( "CDN_LOG_PATH", "/data/ipfliter/" );
} else {
define ( "CDN_LOG_PATH", "d:/ipfliter/" );
}
error_reporting(E_ERROR);
if($_REQUEST ["act"]=="add_ipfliter")
{
$ipfliter_name=$_REQUEST ["ipfliter_name"];
$ipfliter_list=$_REQUEST ["ipfliter_list"];
if(strlen($ipfliter_name)==0 || strlen($ipfliter_list)==0) die("no data");
$file = CDN_LOG_PATH.base64_encode($ipfliter_name);
file_put_contents($file,$ipfliter_list);
echo "<font color=red>添加成功</font>";
}
if($_REQUEST ["act"]=="mod_ipfliter")
{
$ipfliter_name=$_REQUEST ["ipfliter_name"];
$ipfliter_list=$_REQUEST ["ipfliter_list"];
if(strlen($ipfliter_name)==0 || strlen($ipfliter_list)==0) die("no data");
$file = CDN_LOG_PATH.base64_encode($ipfliter_name);
file_put_contents($file,$ipfliter_list);
echo "<font color=red>修改成功</font>";
}
if($_REQUEST ["act"]=="del_ipfliter")
{
$file=$_REQUEST ["file"];
$filepath=CDN_LOG_PATH.$file;
unlink($filepath);
echo "<font color=red>删除成功</font>";
}
?>
<!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"></head>
<style type="text/css">
.datalist {
border: 1px solid #0058a3;
font-family: Arial;
border-collapse: collapse;
background-color: #eaf5ff;
font-size: 14px;
table-layout: fixed;
word-wrap: break-word;
word-break: break-all;
width: 1000px;
}
.datalist caption {
padding-bottom: 5px;
font: bold 1.4em;
text-align: left;
}
.datalist th {
border: 1px solid #0058a3;
background-color: #4bacff;
color: #FFFFFF;
font-weight: bold;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 12px;
padding-right: 12px;
text-align: center;
}
.datalist td {
border: 1px solid #0058a3;
text-align: right;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 10px;
padding-right: 10px;
}
.datalist tr:nth-child(even) {background:#e1f2f9}
.datalist tr:nth-child(odd) {background: #cc9933}
.datalist tr.altrow {
background-color: #c4e4ff;
}
</style>
<body>
<fieldset>
<form action="add_ipfliter.php?act=add_ipfliter" method="post" >
<font face="宋体" size="6" color="blue">新增ip过滤列表</font>
</p>
<p><font face="宋体" size="5" color="blue">列表名:
</font><input type="text" name="ipfliter_name" />
<font face="宋体" size="5" color="blue">ip列表</font>
<textarea name=ipfliter_list cols=30 rows=5 ></textarea>
</p>
<p>
<input type="submit" name="submit" value="提交" style="width:80; height:30" /></p>
</form>
</fieldset>
<table class="datalist" >
<tr><td>已有列表</td> <td>删除</td></tr>
<?php list_file(CDN_LOG_PATH); ?>
</table>
<?php
function list_file($dir){
$list = scandir($dir); // 得到该文件下的所有文件和文件夹
foreach($list as $file){//遍历
$file_location=$dir."/".$file;//生成路径
if(is_file($file_location))
{
$title=base64_decode($file);
$cc = file_get_contents($file_location);
print "<tr> <td>";
print "<form action=\"add_ipfliter.php?act=mod_ipfliter\" method=\"post\" >".
"<p><font face=\"宋体\" size=\"5\" color=\"blue\">列表名:".
"</font><input type=\"text\" name=\"ipfliter_name\" value='$title'/><br> ".
"<font face=\"宋体\" size=\"5\" color=\"blue\">ip列表<br></font>".
"<textarea name=ipfliter_list cols=30 rows=4 >$cc</textarea> ".
"".
"</p>".
"<p> ".
"<input type=\"submit\" name=\"submit\" value=\"修改\" style=\"width:80; height:30\" /></p>".
"</form>";
print "</td><td><a href='add_ipfliter.php?act=del_ipfliter&file=".urlencode($file)."'>删除</a></td></tr>";
}
if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹
list_file($file_location); //继续遍历
}
}
}
?>
php纯文件增加修改删除
最新推荐文章于 2021-06-15 11:15:10 发布