CodeIgniter Forums
Server path - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Server path (/showthread.php?tid=4603)

Pages: 1 2


Server path - El Forum - 12-05-2007

[eluser]theswede[/eluser]
Is there any more convenient way to get the server path version of base_url()?
Code:
$message_path = realpath(dirname(FCPATH)).'media/txt/dvd_competition.txt';



Server path - El Forum - 12-05-2007

[eluser]zdknudsen[/eluser]
Well, any paths to inside your CodeIgniter /system folder or /application folders can be found using the BASEPATH and APPPATH constants respectively.


Server path - El Forum - 12-06-2007

[eluser]theswede[/eluser]
Yes, that I am aware of. But I do not story my css/images/text-files inside these folders. They are stored outside the CodeIgniter directories.

It's for my beta-testing server, the directory structure is as follows:
/system <--- CI sys-dir
/app1/application
/app1/media/[images|css|txt]
/app1 <--- This is the path I want to get


Server path - El Forum - 12-06-2007

[eluser]Michael Wales[/eluser]
The constant APPPATH as defined in the bootstrap file - index.php

I've copy-pasted the relevant lines from throughout that file (from my own installation):
Code:
$system_folder = "../system";
$application_folder = "./";

$system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;

define('BASEPATH', $system_folder.'/');
define('APPPATH', BASEPATH.$application_folder.'/');



Server path - El Forum - 12-06-2007

[eluser]zdknudsen[/eluser]
If you simply need a path to the folder above your application path, then how about this?

$path = APPPATH . '../';


Server path - El Forum - 12-06-2007

[eluser]theswede[/eluser]
That requires that the root folder is placed directly above the root folder of the application. What if it isn't?


Server path - El Forum - 12-06-2007

[eluser]zdknudsen[/eluser]
/system <--- CI sys-dir
/app1/application
/app1/media/[images|css|txt]
/app1 <--- This is the path I want to get

That's the example you gave us, and the /app1 folder is directly above the application folder there.


Server path - El Forum - 12-06-2007

[eluser]tonanbarbarian[/eluser]
I would recommend creating a config file in which you specify this path.

config/message.php
Code:
&lt;?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
$config['message_path'] = '/app1';
then in your controller
Code:
...
$this->config->load('message');
$path = realpath($this->config->item('message_path').'media/txt/dvd_competition.txt');
...



Server path - El Forum - 12-06-2007

[eluser]theswede[/eluser]
Zacharias Knudsen:

I'm sorry if I made you confused. My goal is to make the application as portable as possible. If I were to move the application from one folder to another I'd still want it to work. It should work even if I (in index.php) changed either of the application or system's folder path. This is why I used:
Code:
realpath(dirname(FCPATH));
FCPATH contains the server path to the index.php document. This get's the server path. I'll stick with this, possible combine it with tonanbarbarian's idea and slap it in a config-file somewhere.

Thanks for you help.


Server path - El Forum - 12-06-2007

[eluser]Michael Wales[/eluser]
I already gave you the answer...

you have to define the APPPATH for the application to work - you do this in config.php. What's wrong with just using it?