CodeIgniter-删除文件,出现路径问题 [英] CodeIgniter - Delete file, pathing issue

查看:77
本文介绍了CodeIgniter-删除文件,出现路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的根目录中有3个文件夹:应用程序,系统和上载。在application / controllers / mycontroller.php中,我有这行代码。

I have 3 folders in my root, "application", "system", and "uploads". In application/controllers/mycontroller.php I have this line of code.

delete_files("../../uploads/$file_name");

文件没有被删除,我尝试了许多路径选项,如../和。 。/../../ 有任何想法吗?谢谢。

The file does not get deleted and I have tried a number of pathing options like ../ and ../../../ any ideas? Thanks.

推荐答案

$ file_name 是一个变量。您应该将其连接到自己的字符串以执行该功能:

$file_name is a variable. You should concatenate it to your own string in order to execute the function:

delete_files("../../uploads/" . $file_name);

编辑:

请确保以下句子:

echo base_url("uploads/" . $file_name);

正在回显有效路径。如果答案为是,请尝试以下操作:

Is echoing a valid path. If the answer is YES, try this:

$this->load->helper("url");
delete_files(base_url("uploads/" . $file_name));

假设您的上载文件夹位于根目录中。

Supposing that your "uploads" folder is in your root directory.

编辑2:

使用 unlink 函数:

$this->load->helper("url");
unlink(base_url("uploads/" . $file_name));

这篇关于CodeIgniter-删除文件,出现路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆