I have a simple test file:
<html><body>
<?php
echo "root_include.php:<br />\n";
include("/root_include.php");
echo "local_include.php:<br />\n";
include("local_include.php");
?>
</body></html>
The "local_include.php" file is found just fine, but "/root_include.php" isn't. It's possible I have a spelling error, but I've double checked it a couple of times now. What I'd really like to do is not have to use relative paths, which are clumsy and lock me in to specific directory structures.
Here's a typical error message:
[22-Sep-2009 21:19:30] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/root_include.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/redacted/public_html/test/include_test.php on line 4
Edit:
Thanks for this reply, descalzo, our posts crossed so if you're wondering why my post just above this one doesn't make much sense, I was not reply to you.
You do not have to mess with the include path.
You can supply an absolute path to require/include
PHP:
require_once( '/home/yourusername/etc/db_pass.txt') ;
This one isn't very feasible because my home directory will change if the app gets moved elsewhere.
Or you can supply a relative path...
PHP:
require_once( '../etc/db_pass.txt') ; [if your script is in /public_html]
require_once( '../../etc/db_pass.txt') ; [if your script is in a subdirectory of /public_html]
You do not have to adjust the include path.
Again, if the internal directory structure of my PHP app gets changed (i.e., I want to change the locations of some files around), I'd have a large headache chasing down these relative strings and re-typing them.
But if you insist...
PHP:
$path = '/the/additional/path';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
will add your additional path for that one script.
This seems to be what I was looking for. At least, my paths should be in one spot, or at most one string per file to set the path string. Should be much nicer in the long run. Thanks!
Edit:
Well, crud, seems I hit the "edit" button. Sorry about the mess.