CodeIgniter:如何从文件夹中删除上传的图像 [英] CodeIgniter : How to delete uploaded image from folder
本文介绍了CodeIgniter:如何从文件夹中删除上传的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不仅要删除数据库中的图像,还要删除文件夹中的图像。
I want to delete the image not only in database, but in folder too.
这是我的数据库表:
group_id
group_name
group_descrtion
group_picture
这是我的控制器:
public function delete_group()
{
$group_id = $this->input->post('group_id');
$group_picture = $this->input->post('group_picture');
$this->group_model->delete_group($group_id, $group_picture);
redirect('product_group');
}
这是我的模型:
function delete_group($group_id, $group_picture)
{
$this->db->where('group_id', $group_id);
unlink(base_url("uploads/".$group_picture));
$this->db->delete('product_group', array('group_id' => $group_id));
}
这是我的观点:
<?=form_open_multipart('product_group/delete_group');?>
<input type="hidden" class="form-control" placeholder="Group ID" name="group_id">
<input type="text" class="form-control" placeholder="Group ID" name="group_picture">
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
我成功删除了数据库中的数据,但是文件夹中的图像也没有被删除。
I succeed in deleting the data in the database, but the image in the folder are not also be deleted.
感谢您的帮助:)
推荐答案
unlink(base_url("uploads/".$group_picture));
应该是
unlink("uploads/".$group_picture);
您需要路径,而不是URL。
You need the path, not the url.
这篇关于CodeIgniter:如何从文件夹中删除上传的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文