Jump to content

Windows + Server Compatible Include Path


Praetorian
 Share

Recommended Posts

I'm trying to write a script that will install itself on someones server (like a forum script). But I want most of the class files to exist above the public_html folder. So I need the script to be able to add them to the include path. I'm having trouble making that work though. I can make it work when the files are in the same folder as the file setting the include paths, but when I have them in separate directories (IE, a header file in the public_html directory setting the include paths, but for directories above the header file). Also, (and this part isn't a requirement) I'd like it to be compatible with both windows and linux, since I'll be building this on my localhost, but it will eventually be running on a linux server (most likely).It may be that I just don't understand how to use the ini_set/set_include_path functions correctly. Does anyone have a quick example of something they're using on their own scripts that works?Thanks in advance.

Link to comment
Share on other sites

They have this example to add a path to the existing include path:

<?php$path = '/usr/lib/pear';set_include_path(get_include_path() . PATH_SEPARATOR . $path);?>

You need to use the absolute path, you shouldn't use a relative path for an include path. From wherever you set the include path, you can use a combination of the dirname function and __FILE__ constant to get a path above the directory of the current script. e.g.:$path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'include';

Link to comment
Share on other sites

Okay that actually didn't work the way I wanted. Using that returnsC:\xampp\www\cms.com\public_html\cms_libraryWhen what I need is C:\xampp\www\cms.com\cms_libraryjustsomeguys answer was mostly correct though, just needed an extra dirname, since the folder I want is above my root directory. So the solution is..

$path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'include';

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...