tibberous Posted August 13, 2008 Share Posted August 13, 2008 This one is hard to explain, so I'll use an example. I have include files: smptemail.php actions/emailfunctions.php And emailfunctions includes smptemail.php as ../smptemail.php. And this works, UNLESS emailfunctions.php if referenced from a directory other than the root one. I can think of four solutions. - Use symbolic links - Copy the text of smptemail into emailfunctions - Hard code paths - include based on file_exists. I'm going to probably go with four, but is there a better way to handle this? Like an include that looks for includes relative to the including file, not the main file? Link to comment https://forums.phpfreaks.com/topic/119521-is-there-a-way-to-include-a-file-relative-to-another-file/ Share on other sites More sharing options...
geudrik Posted August 13, 2008 Share Posted August 13, 2008 Try using... $_SERVER['DOCUMENT_ROOT'] and creating a string thats essentially absolute. Link to comment https://forums.phpfreaks.com/topic/119521-is-there-a-way-to-include-a-file-relative-to-another-file/#findComment-615752 Share on other sites More sharing options...
tibberous Posted August 13, 2008 Author Share Posted August 13, 2008 You know what, that might not be a bad idea. I'm using a lot of subdomains, which change it, but I almost forgot that was even an option. Link to comment https://forums.phpfreaks.com/topic/119521-is-there-a-way-to-include-a-file-relative-to-another-file/#findComment-615759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.