Browse Source

添加删除

old
xiaoz 7 years ago
parent
commit
3f6054d4d6
  1. 31
      admin/pics.php
  2. 17
      api/PublicClass.php
  3. 38
      api/delete.php
  4. 3
      api/functions.php

31
admin/pics.php

@ -30,10 +30,10 @@
<?php for($i = 0;$i < 12;$i++){ <?php for($i = 0;$i < 12;$i++){
$imgurl = $config['domain'].$listpic[$i]['dir']; $imgurl = $config['domain'].$listpic[$i]['dir'];
?> ?>
<tr> <tr id = "row<?php echo $listpic[$i]['id']; ?>">
<td><a href="javascript:;" onclick = "showimg('<?php echo $imgurl ?>');"><?php echo $listpic[$i]['dir']; ?></a></td> <td><a href="javascript:;" onclick = "showimg('<?php echo $imgurl ?>');"><?php echo $listpic[$i]['dir']; ?></a></td>
<td><a href="javascript:;"><?php echo $listpic[$i]['date']; ?></td> <td><a href="javascript:;"><?php echo $listpic[$i]['date']; ?></td>
<td><a href="javascript:;" class = "layui-btn layui-btn-danger layui-btn-xs" onclick = "delimg();">删除</a></td> <td><a href="javascript:;" class = "layui-btn layui-btn-danger layui-btn-xs" onclick = "delimg(<?php echo $listpic[$i]['id']; ?>);">删除</a></td>
</tr> </tr>
<?php } ?> <?php } ?>
</tbody> </tbody>
@ -56,17 +56,22 @@
}); });
} }
//删除图片 //删除图片
function delimg(){ function delimg(id){
layer.confirm('纳尼?', { var msg = "确认删除?";
btn: ['按钮一', '按钮二', '按钮三'] //可以无限个按钮 var id = id;
,btn3: function(index, layero){ if (confirm(msg)==true){
//按钮【按钮三】的回调 $.get("../api/delete.php?id="+id,function(data,status){
} //删除成功
}, function(index, layero){ if(data == 'ok') {
//按钮【按钮一】的回调 $("#row"+id).remove();
}, function(index){ }
//按钮【按钮二】的回调 else{
}); alert(data); //删除失败,弹出报错
}
});
}else{
return false;
}
} }
</script> </script>

17
api/PublicClass.php

@ -0,0 +1,17 @@
<?php
include_once("../config.php");
class LgoinStatus {
var $uid = $_COOKIE['uid'];
var $login = md5($config['username'].$config['password']);
function status(){
$uid = $this->uid;
$loginid = $this->login;
if($uid != $loginid) {
return false;
echo '权限不足';
exit;
}
}
}
?>

38
api/delete.php

@ -0,0 +1,38 @@
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
include_once('../config.php');
$uid = $_COOKIE['uid'];
$loginid = md5($config['username'].$config['password']);
if($uid != $loginid) {
echo '权限不足';
exit;
}
//图片ID
$id = $_GET['id'];
$imginfo = $database->get("uploads",["id","dir"],["id" => $id]);
//如果查询到了ID
if($imginfo) {
//如果文件删除成功
if(unlink("../".$imginfo['dir'])) {
//删除数据库记录
$delinfo = $database->delete("uploads",["id" => $id]);
if($delinfo) {
echo 'ok';
}
else{
echo '数据库删除失败';
exit;
}
}
else{
echo '删除失败,可能是文件不存在';
}
}
else {
echo 'ID不存在';
exit;
}
?>

3
api/functions.php

@ -0,0 +1,3 @@
<?php
?>
Loading…
Cancel
Save