Codeigniter - 动态获取应用程序文件夹外的相对/绝对路径 [英] Codeigniter - dynamically getting relative/absolute path outside of application folder

查看:32
本文介绍了Codeigniter - 动态获取应用程序文件夹外的相对/绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在应用程序文件夹之外并与应用程序文件夹处于同一级别的各种临时缓存文件夹.这是为了在将图像移到异地之前将图像存储片刻.

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__)(__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?

In the index.php file in the root, most useful paths are defined so that you can use them within the rest of the code. Have you tried FCPATH in this case?

FCPATH   -> '/'
BASEPATH -> '/system/'
APPPATH  -> '/application/'

更新:如评论中所述,上面的路径示例仅用于概述.为了提高项目的安全性,BASEPATHAPPPATH 不会在 FCPATH 内,而是在公共 www/root 目录.

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屋!

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