Codeigniter - 动态获取应用程序文件夹之外的相对/绝对路径 [英] Codeigniter - dynamically getting relative/absolute path outside of application folder
问题描述
我试图有一个临时缓存文件夹,只是在应用程序文件夹之外,并在同一级别。这是为了在将图片移动到现场之前存储图片。
I am attempting to have a temporary cache folder of sorts just outside of and at the same level as the application folder. This is for storing images for a couple moments before moving them off-site.
我想要获取用户的Facebook个人资料图片并将其保存到我的服务器。我有一个图像存储解决方案,要求我拍照,并重命名,然后将其传递到相应的位置进行存储。我的想法是使用 file_get_contents()
和 file_put_contents()
然后将其复制/移动到我的存储方法。但是我不希望在应用程序文件夹中有临时目录 - 我想要与应用程序和系统文件夹在同一级别。我的问题是访问相对路径或绝对路径(在应用程序文件夹的同一级别),而不对其进行硬编码。
I am trying to get a user's Facebook profile image and save it to my server. I have an image storage solution which requires me to take the photo, and rename it then pass it to the respective location for storage. My thoughts were using file_get_contents()
and file_put_contents()
I could store this file for a moment while processing it accordingly and then copy/move it to my storage method. However I do not wish to have the temp directory inside of the application folder - I want to have it at the same level as the application and system folder. My problem is accessing a relative path or absolute path (at the same level of the application folder) without hardcoding it.
使用(__ dir __) / code>,
(__ file __)
,像 realpath(APPPATH)
应用程序文件夹。所以我希望别人知道一种方法来实现这个
Using (__dir__)
, (__file__)
, and something like realpath(APPPATH)
only gives me results within the application folder. So I am hoping someone else knows a way to achieve this
推荐答案
在 index.php
文件在根中,最有用的路径被定义,以便可以在其余代码中使用它们。在这种情况下,您是否尝试过
FCPATH
?
FCPATH -> '/'
BASEPATH -> '/system/'
APPPATH -> '/application/'
UPDATE:上面的路径示例只是给出了概述。为了增加项目的安全性, BASEPATH
和 APPPATH
不会位于 FCPATH
,而不在公共 www
/ 目录
UPDATE: As mentioned in the comments, the path examples above are only to give an overview. To increase the security of your project, BASEPATH
and APPPATH
wouldn't be inside FCPATH
and instead outside of the public www
/root
directory.
这篇关于Codeigniter - 动态获取应用程序文件夹之外的相对/绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!