CodeIgniter Forums
I need to include a file outside of the codeigniter directory - 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: I need to include a file outside of the codeigniter directory (/showthread.php?tid=21798)



I need to include a file outside of the codeigniter directory - El Forum - 08-20-2009

[eluser]next2heaven[/eluser]
I have a file from a form that I need to include. It will gather the users information (if they are logged in, etc). It returns and sets a bunch of stuff and I don't want to have to put it into CI. It's meant to be included outside of the form for that purpose.

How do I call that file? I've tried something like this:

$this->load->file('/community/ssi.php');

but that didn't work (even tried full path to file but it errors out saying: 'URL file-access is disabled in server configuration' ...not sure what to change). Any ideas?


I need to include a file outside of the codeigniter directory - El Forum - 08-20-2009

[eluser]fesweb[/eluser]
Never mind, i mis-read your post...


I need to include a file outside of the codeigniter directory - El Forum - 08-20-2009

[eluser]skunkbad[/eluser]
In the actual php language, there are two ways to include other php files. There may be a CI solution, and if so, I'm sure somebody else will chime in.

#1: include '/home/~learn/php/and/you/would/not/need/to/ask/this/question.php';

#2: require '/home/~learn/php/and/you/would/not/need/to/ask/this/question.php';

You can also use _once on the end, and this makes it so that the include can only be loaded once.

include_once ''; or require_once '';

"require" is used when you want to load something, and if it fails to load the script will die. Using "include" will allow the script to keep running if it fails to load the included file.

The php manual is at php.net, and if you haven't read it, you really should. It's very awesome.


I need to include a file outside of the codeigniter directory - El Forum - 08-20-2009

[eluser]next2heaven[/eluser]
Ya...when I used those, that's when it gives me the error as well. So perhaps it's not a CI issue? I'm running MAMP locally but I've got the php.ini configured to allow it. Not sure what's up.


I need to include a file outside of the codeigniter directory - El Forum - 08-20-2009

[eluser]next2heaven[/eluser]
Got it to work. Used the following:

require($_SERVER['DOCUMENT_ROOT'].'/community/SSI.php');