[谁能帮我,我想从文件夹codeigniter删除文件,这是我的控制器
public function delete($id = false) {
if (!$id)
show_404();
$this->{$this->model}->{$this->_primary_key} = $id;
$data['item'] = $this->{$this->model}->get();
if (!$data['item'])
show_404();
$this->{$this->model}->delete();
redirect('admin/' . $this->module);
}
public function image($var, $id) {
$config['upload_path'] = './cdn/sliders/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
$data = $this->upload->data();
if ($data['file_name'])
$this->{$this->model}->image = $data['file_name'];
}
return true;
}
就像
public function delete_video($id)
{
$this->db->where('id', $id);
$this->db->select('video');
$video_name = $this->db->get('vs_videos')->row_array();
if ($video_name) {
@unlink('./vs_asset/videos/' . $video_name['video']);
$this->db->where('id', $id)
->delete('vs_videos');
$result = $this->db->affected_rows();
return $result;
} else {
return;
}
}
$filename = file_name_with_full_path
您可以使用unlink($ filename)函数删除php中的文件
请查看下面的链接了解详细信息
非常感谢,我得到了答案
这里是如何工作的。
public function delete($id = null) {
if (!$id)
show_404();
$this->{$this->model}->{$this->_primary_key} = $id;
$path = './cdn/projects/';
$data['item'] = $this->{$this->model}->get();
if (!$data['item'])
show_404();
@unlink($path.$data['item']->image);
$this->{$this->model}->delete();
redirect('admin/' . $this->module);
}