I am trying to delete all user data including all images from 'uploads' folder when deleted a record in XAMPP. So far it is deleting rows from table but for the images from upload folder I get this error,
Message: unlink(uploads/property-images/): Permission denied
When I print_r($rowId);
from model it echo the images array fine. I am sure that I may be doing something wrong in model as delete function has to be an array on it but I am not sure how to do that.
But at the same time in my other scripts I have successfully deleted and replace user's profile picture using unlink.. I guess if that worked than 'Permission' shouldn't be the problem this time.. The only difference is that this time I have an array of images exploded in script.
In my controller:
function delete_listing_id() {
if($this->session->userdata('is_logged_in')){
$id = $this->uri->segment(3);
$images_urls = $this->my_listings_model->get_property_all_images_url($id);
$this->my_listings_model->delete_listing_images($images_urls);
$this->my_listings_model->delete_listing_id($id);
$this->my_listings();
}
Model:
function get_property_all_images_url($id) {
$this->db->select('property_images');
$this->db->from('vbc_property_images');
$this->db->where('property_ref_id', $id);
$query = $this->db->get();
$query_result = $query->result_array();
if (empty($query_result)) {
return FALSE;
}
elseif (count($query_result) > 1) {
return 0;
}
else{
$rowId = explode(',',$query_result[0]['property_images']);
return $rowId;
}
}
function delete_listing_id($id){
$this->db->delete('vbc_vacation_item_attri', array('vbc_item_id' => $id));
$this->db->delete('vbc_property_amenities', array('v_ref_id' => $id));
$this->db->delete('vbc_property_images', array('property_ref_id' => $id));
}
function delete_listing_images($images_urls) {
unlink('uploads/property-images/'.$images_urls);
return TRUE;
}