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 @@ @@ -30,10 +30,10 @@
<?php for($i = 0;$i < 12;$i++){
$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:;"><?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>
<?php } ?>
</tbody>
@ -56,17 +56,22 @@ @@ -56,17 +56,22 @@
});
}
//删除图片
function delimg(){
layer.confirm('纳尼?', {
btn: ['按钮一', '按钮二', '按钮三'] //可以无限个按钮
,btn3: function(index, layero){
//按钮【按钮三】的回调
}
}, function(index, layero){
//按钮【按钮一】的回调
}, function(index){
//按钮【按钮二】的回调
});
function delimg(id){
var msg = "确认删除?";
var id = id;
if (confirm(msg)==true){
$.get("../api/delete.php?id="+id,function(data,status){
//删除成功
if(data == 'ok') {
$("#row"+id).remove();
}
else{
alert(data); //删除失败,弹出报错
}
});
}else{
return false;
}
}
</script>

17
api/PublicClass.php

@ -0,0 +1,17 @@ @@ -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 @@ @@ -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 @@ @@ -0,0 +1,3 @@
<?php
?>
Loading…
Cancel
Save