使用 CodeIgniter 删除文件?
我不确定这是否是使用 CodeIgniter 删除单个文件(例如图像)的正确函数。
$this->load->helper('file');
delete_files('path')
http://codeigniter.com/user_guide/helpers/file_helper.html
但是它列出了该函数用于删除整个目录,并且没有提及它如何处理单个文件(如果仅给出 1 个文件的路径)。在开始测试之前,我想我应该检查一下是否有人遇到过这个问题?
我只是想使用 CodeIgniter 函数来删除单独上传的图像(例如用户个人资料图像),但我无法在文档/用户指南中找到任何可以帮助我实现此目的的内容(是的,我知道我首先需要拥有适当的权限那个,但这超出了这个问题的范围)。
关于 unlink()
我所希望的是一个内置的 CI 函数,它会提醒我一些愚蠢的事情,例如“无删除权限”或其他因素,例如“文件正在使用”。我发现 unlink() 有时不起作用(不会抛出错误)。所以我才问...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在评论中发布的,您可以利用 PHP 的
unlink()
函数。但是,这似乎在返回 false 时返回E_WARNING
错误。就像我在评论中所说的那样,您可以利用错误抑制,但如果无法删除文件,仍然以适当的方式处理错误。As I posted in the comments, you could utilize PHP's
unlink()
function. However, this seems to return anE_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.