Praetorian Posted May 29, 2009 Share Posted May 29, 2009 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 More sharing options...
justsomeguy Posted May 29, 2009 Share Posted May 29, 2009 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 More sharing options...
Praetorian Posted May 29, 2009 Author Share Posted May 29, 2009 Thanks justsomeguy! That worked perfectly. Link to comment Share on other sites More sharing options...
Praetorian Posted May 30, 2009 Author Share Posted May 30, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.