Deleting a File using php/codeigniter

Jetoox picture Jetoox · Mar 17, 2012 · Viewed 82.9k times · Source

I would like to delete a file that is found in my localhost.

localhost/project/folder/file_to_delete

I'm using codeigniter for this.

I would like to use the unlink() function in php but I really can't understand how to use it.

Answer

Taha Paksu picture Taha Paksu · Mar 17, 2012

you can use the "file helper" in codeigniter.

CodeIgniter v3: http://codeigniter.com/userguide3/helpers/file_helper.html#delete_files

CodeIgniter v4: http://codeigniter.com/user_guide/helpers/filesystem_helper.html#delete_files

and like this :

$this->load->helper("file");
delete_files($path);

Late Edit: delete_filesmethod uses a path to wipe out all of its contents via unlink() and same you can do within CI. Like this:

unlink($path); 

a valid path.