Reputation: 1866
I have upload images in rooturl + uploads/slider and image name store in database slider_image.
I want to delete slider_image from databse and also delete from folder.
my folder location :
http://localhost/game/uploads/slider/soccer.jpg
image_name:
soccer.jpg
I got an warning error :
Severity: Warning
Message: unlink(): http does not allow unlinking
my model code:
public function deleteSlider($sliderID)
{
$this->db->delete('slider_tbl',array('slider_id' => $sliderID));
$path = base_url("uploads/slider/".$result[0]->slider_image);
if($this->db->affected_rows() >= 1){
if(unlink($path))
return TRUE;
} else {
return FALSE;
}
}
Upvotes: 0
Views: 3415
Reputation: 456
Try Changing your $path
.
$path = base_url("uploads/slider/".$result[0]->slider_image);
to
$path = "./uploads/slider/" . $result[0]->slider_image;
Upvotes: 1
Reputation: 7111
Change
$path = base_url("uploads/slider/".$result[0]->slider_image);
to
$path = FCPATH . "uploads/slider/" . $result[0]->slider_image;
Upvotes: 1
Reputation: 76426
You need to use the path to the file on the server, not the URL, so you need something like:
$path = "/uploads/slider/".$result[0]->slider_image;
without the base_url
.
Upvotes: 0