44

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.

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

Codebling
  • 10,764
  • 2
  • 38
  • 66
chris
  • 36,115
  • 52
  • 143
  • 252

1 Answers1

134

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/'

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.

Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
  • didn't even think to look back in the index.php, long while back I learned about the `APPPATH` and rarely have I ever had a need to anything otherwise. But this just did exactly what I was seeking. Thank you – chris Mar 06 '13 at 09:17
  • You're welcome. I found it a bit strange that you knew how to use `APPPATH`, but not `FCPATH` :) – Robin Castlin Mar 06 '13 at 10:40
  • 1
    I find it a bit strange myself haha, concidering there was a time I crawled up and down CI to figure similar things out. But its always the simple things that evade me, more so when Im deep in the trenches trying to figure something else out from one aspect or another, then turn around and make it more difficult than it needs be. Ironically before you replied I was even thinking of going into the index.php and defining something myself as a last ditch effort, then you answered, and reminded me there already was :-) – chris Mar 06 '13 at 19:55
  • 1
    For the most secure CI installation, the `system` and `application` folders should be installed _outside_ of the `www` or public root directory. One should note in that case, `FCPATH` would NOT be located at the root of `system` and `application `. `FCPATH` represents the `www` directory (where `index.php` is located; FC = Front Controller). In other words, the directory structure shown in this answer only works when the `system` and `application` folders are installed within the `www` directory. – Sparky Oct 19 '14 at 22:35
  • That's true, Sparky. Added to the answer. – Robin Castlin Oct 20 '14 at 09:29