public function deleteuser()
{
$this->sql = " SELECT admin_img FROM admin_data WHERE admin_id = '$this->admin_id' ";
$this->res = mysqli_query($this->conxn, $this->sql)
or trigger_error($this->err = mysqli_error($this->conxn));
$this->numRows = mysqli_num_rows($this->res);
$this->data = mysqli_fetch_assoc($this->res);
//filename
$file_name = $this->data['admin_img'];
$destination="Uploads/".$file_name;
//delete the file
if(file_exists($destination)){
if(unlink($destination)){
//file removed from the server
//now remove from the database
$this->sql = " DELETE FROM admin_data WHERE admin_id = '$this->admin_id' ";
$this->res = mysqli_query($this->conxn, $this->sql)
or trigger_error($this->err = mysqli_error($this->conxn));
$this->affRows = mysqli_affected_rows($this->conxn);
echo $this->affRows;
if($this->affRows>0){
return TRUE;
}
else{
return FALSE;
}
else{
return FALSE;
}
}//delete file ends
我已经解除了我上传的文件的链接,但我可以删除我在添加用户文件时存储的数据。我也没有得到任何错误,但代码总是返回False我希望代码返回真值。
请帮助我****提前致谢
尝试在您的unlink if条件
解除链接时需要给出根路径
if(file_exists($_SERVER['DOCUMENT_ROOT'].$destination)){
if(unlink($_SERVER['DOCUMENT_ROOT'].$destination)){
//your delete code
}
}