CodeIgniter Forums
How to delete the file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How to delete the file (/showthread.php?tid=63656)



How to delete the file - jdk - 11-23-2015

Hello. Please forgive me for so newbie question, however I have already read documentation several times, but I didn't find an answer.
I have to delete file which is placed on $file = base_url()."uploads/images/".$filename
Please give me some examples how to do it?


RE: How to delete the file - Diederik - 11-24-2015

File deletion is not part of a framework but a native php function. You are looking for the function unlink() (http://php.net/manual/en/function.unlink.php)

A small note, you cant delete a file based on the URL, the example you provide refers to a url (http://somedomain.com/uploads/images/somefile.jpg), you need to provide the (filebased) path to the file, for example:

PHP Code:
unlink(APPPATH '/uploads/images/somefile.jpg'); 



RE: How to delete the file - meow - 01-22-2016

(11-24-2015, 03:20 AM)Diederik Wrote: File deletion is not part of a framework but a native php function. You are looking for the function unlink() (http://php.net/manual/en/function.unlink.php)

A small note, you cant delete a file based on the URL, the example you provide refers to a url (http://somedomain.com/uploads/images/somefile.jpg), you need to provide the (filebased) path to the file, for example:

PHP Code:
unlink(APPPATH '/uploads/images/somefile.jpg'); 

Thanks! Here are some more paths listed under CONSTANTS:
http://www.codeigniter.com/user_guide/general/reserved_names.html?highlight=apppath