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.
To delete a file in PHP, use the unlink function. Let's go through an example to see how it works. The first argument of the unlink function is a filename which you want to delete. The unlink function returns either TRUE or FALSE , depending on whether the delete operation was successful.
PHP | unlink() Function The unlink() function is an inbuilt function in PHP which is used to delete files.
If you require to get only one record from database table using codeigniter query then you can do it using row(). we can easily return one row from database in codeigniter.
unlink(base_url(). '/image/logo_thumb'. $logo_thumb);
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_files
method 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With