php Codeigniter - 动态获取应用程序文件夹外的相对/绝对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15242972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter - dynamically getting relative/absolute path outside of application folder
提问by chris
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.
我正在尝试在应用程序文件夹之外并与应用程序文件夹处于同一级别的各种临时缓存文件夹。这是为了在将图像移出现场之前将图像存储片刻。
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.
我正在尝试获取用户的 Facebook 个人资料图片并将其保存到我的服务器。我有一个图像存储解决方案,需要我拍摄照片,重命名它,然后将其传递到相应的位置进行存储。我的想法正在使用file_get_contents(),file_put_contents()我可以存储这个文件片刻,同时相应地处理它,然后将它复制/移动到我的存储方法。但是我不希望在应用程序文件夹中有临时目录 - 我希望它与应用程序和系统文件夹处于同一级别。我的问题是访问相对路径或绝对路径(在应用程序文件夹的同一级别)而不对其进行硬编码。
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
使用(__dir__)、(__file__)和类似的东西realpath(APPPATH)只会在应用程序文件夹中给我结果。所以我希望其他人知道实现这一目标的方法
回答by Robin Castlin
In the index.phpfile in the root, most useful paths are defined so that you can use them within the rest of the code. Have you tried FCPATHin this case?
在index.php根目录中的文件中,定义了最有用的路径,以便您可以在其余代码中使用它们。你FCPATH在这种情况下尝试过吗?
FCPATH -> '/'
BASEPATH -> '/system/'
APPPATH -> '/application/'
UPDATE:As mentioned in the comments, the path examples above are only to give an overview. To increase the security of your project, BASEPATHand APPPATHwouldn't be inside FCPATHand instead outside of the public www/rootdirectory.
更新:如评论中所述,上面的路径示例仅用于概述。为了提高项目的安全性,BASEPATH而APPPATH不会在里面FCPATH,而是在外面的公共www/root目录。

