php - 无法从目录中删除图像,但数据已成功从 codeigniter 中的数据库中删除
问题描述
我无法从目录中删除图像,但数据成功从数据库中删除。请我需要帮助。
下面是我的控制器
public function hapus(){
$id = $this->input->get('id');
/* query showing image for deleting image first before delete it from database */
$path = './asset/uploads/';
$path1 = './asset/hasil_resize/';
$arraydelete = array('id'=>$id);
$rowdel = $this->Model_upldgbr->get_byimage($arraydelete);
/* the image delete from folder */
@unlink($path.$path1.$rowdel->namafile);
$this->Model_upldgbr->get_delete($arraydelete);
$this->session->set_flashdata("pesan", "<div class=\"col-md-12\"><div class=\"alert alert-danger\" id=\"alert\">Success deleting the image and data !!</div></div>");
redirect('root/upload');
}
这是我的模型
function get_delete($where){
$this->db->where($where);
$this->db->delete($this->tabel);
return TRUE;
}
//function for showing data one by one from the table
function get_byimage($where) {
$this->db->from($this->tabel);
$this->db->where($where);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->row();
}
}
}
删除按钮链接是这样的:
<a href="<?=base_url()?>index.php/root/upload/hapus/?id=<?=$row->id?>"><i class="fa fa-trash-o"></i></a>
解决方案
希望对你有帮助 :
使用两种unlink
方法从两个文件夹中删除文件FCPATH
,应该是这样的
$path = FCPATH.'asset/uploads/';
$path1 = FCPATH.'asset/hasil_resize/';
@unlink($path.$rowdel->namafile);
@unlink($path1.$rowdel->namafile);
//Or better use ci file helper's `delete_files()` method
更多信息:https ://www.codeigniter.com/user_guide/general/reserved_names.html
推荐阅读
- javascript - 有什么方法可以更改 cypress 中的“envFile”变量路径?
- database - Spring JPA - 应用 WHERE 子句乘以嵌套表
- c# - 满足条件时C#linq如何从谓词列表中获取属性
- angular - 从 Nebular 窗口组件打开 Nebular 对话框
- android - 删除 @JvmSuppressWildcards 不起作用 android dagger 2.25.2
- java - 我有一个带有数字和字母的字符串,有没有办法将整数移动到一个单独的 int 变量中?
- javascript - 如果用户输入与预定义字符串匹配,则返回 true
- django - 菜单中的 Django CMS 图标
- android - 领域避免更新嵌套对象
- angular - 我需要帮助了解如何将此函数转换为流以获得响应和最新的结果