//删除备份数据
public function unLinkDate()
{
$session = $_SESSION['userName'];
if(empty($session)) $this->ajaxReturn('','未登录!',-1);
$id = $this->_post('id');
$db = M('datapath');
$where['id'] = $id;
$result = $db->where($where)->select();
if($result){
$data_Path = $result[0]['path'];
$filename = $result[0]['filename'];
$file_Path = $data_Path.$filename;
if(file_exists($file_Path)){
$res = $db->where($where)->delete();
if($res){
if(!unlink($file_Path)) $this->ajaxReturn('','删除失败!',-2);
$this->ajaxReturn('','删除成功!',1);
}else{
$this->ajaxReturn('','删除失败!',-3);
}
}else{
$this->ajaxReturn('','文件不存在!',-4);
}
}else{
$this->ajaxReturn('','没有此数据!',-5);
}
}
public function unLinkDate()
{
$session = $_SESSION['userName'];
if(empty($session)) $this->ajaxReturn('','未登录!',-1);
$id = $this->_post('id');
$db = M('datapath');
$where['id'] = $id;
$result = $db->where($where)->select();
if($result){
$data_Path = $result[0]['path'];
$filename = $result[0]['filename'];
$file_Path = $data_Path.$filename;
if(file_exists($file_Path)){
$res = $db->where($where)->delete();
if($res){
if(!unlink($file_Path)) $this->ajaxReturn('','删除失败!',-2);
$this->ajaxReturn('','删除成功!',1);
}else{
$this->ajaxReturn('','删除失败!',-3);
}
}else{
$this->ajaxReturn('','文件不存在!',-4);
}
}else{
$this->ajaxReturn('','没有此数据!',-5);
}
}
本文介绍了一个用于删除指定ID的备份数据文件的PHP方法。该方法首先验证用户是否已登录,然后根据提供的ID从数据库中获取文件路径及名称,接着尝试删除数据库记录及文件系统中的对应备份文件,并通过AJAX返回操作结果。
682

被折叠的 条评论
为什么被折叠?



