Ali Zia Ali Zia -4 years ago 119
PHP Question

Codeigniter Unlink doesn't work

I want to delete an image before deleting an entry so I did this

$query = $this->db->get_where('info', array("id" => $info_id));
$results = $query->result_array();
echo base_url().'theme/transport/images/services/thumbs/' . $results[0]['image'];die();
unlink(base_url().'theme/transport/images/services/thumbs/' . $results[0]['image']);


But the file is still there. It doesn't unlink. What am I doing wrong?

Answer Source

You should try use FCPATH

unlink(FCPATH .'theme/transport/images/services/thumbs/' . $results[0]['image']);

path functions definitions

EXT: The PHP file extension
FCPATH: Path to the front controller (this file) (root of CI)
SELF: The name of THIS file (index.php)
BASEPATH: Path to the system folder
APPPATH: The path to the "application" folder
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download