Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a File using php/codeigniter

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.

like image 441
Jetoox Avatar asked Mar 17 '12 06:03

Jetoox


People also ask

How to Delete the file using php?

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.

Which function is used in php to Delete a file?

PHP | unlink() Function The unlink() function is an inbuilt function in PHP which is used to delete files.

How do I get my single record in CI?

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.

How do I unlink an image in CI?

unlink(base_url(). '/image/logo_thumb'. $logo_thumb);


1 Answers

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.

like image 98
Taha Paksu Avatar answered Sep 28 '22 02:09

Taha Paksu