Deleting files using CodeIgniter?
I'm not sure if this is the proper function to delete a single file (say an image) using CodeIgniter.
$this->load->helper('file');
delete_files('path')
http:/开发者_运维技巧/codeigniter.com/user_guide/helpers/file_helper.html
However it lists that this function is to delete entire directories, and makes no mention of how it handles individual files (if a path to only 1 file is given). Before I start testing with it, I figured I would check if anyone has ran into this problem before?
I simply want to use a CodeIgniter function to delete individually uploaded images (say user profile images) but I am unable to find anything in the documentation / user guide that helps me achieve this (yes I know I need to have proper permissions first and all that, but that is out of scope of this question).
regarding unlink()
what I was hoping for is a built in CI function that would alert me to something stupid like "no delete permission" or other factors like "file is in use". I found unlink() to sometimes not work (without throwing me an error). Hence why I asked...
As I posted in the comments, you could utilize PHP's unlink()
function. However, this seems to return an E_WARNING
error upon returning false. Like I also stated in the comments, you could utilize error suppression, but still handle the error in an appropriate manner, should it fail to delete a file.
精彩评论