Nematode128 Posted April 11, 2020 Share Posted April 11, 2020 (edited) How do you include files from a higher up directory? I'm currently working on a file in public_html/Directory/otherdirectory and want to include a config file that's in public_html/Directory so how would I include public_html/Directory/config.php in the public_html_Directory/otherdirectory/index.php file? I've tried using ../ and ../Directory/ in the includes line but got errors both times Edited April 11, 2020 by Nematode128 Quote Link to comment https://forums.phpfreaks.com/topic/310529-how-to-include-files-from-a-parent-directory/ Share on other sites More sharing options...
gizmola Posted April 11, 2020 Share Posted April 11, 2020 Based on your description: include "../config.php"; If that is not working, then there is something else going wrong besides the path issue. What error do you get? Quote Link to comment https://forums.phpfreaks.com/topic/310529-how-to-include-files-from-a-parent-directory/#findComment-1576692 Share on other sites More sharing options...
maxxd Posted April 11, 2020 Share Posted April 11, 2020 11 hours ago, Nematode128 said: got errors both times It might help to post those errors here. Quote Link to comment https://forums.phpfreaks.com/topic/310529-how-to-include-files-from-a-parent-directory/#findComment-1576706 Share on other sites More sharing options...
requinix Posted April 11, 2020 Share Posted April 11, 2020 Sometimes PHP does unexpected things when you give it relative paths. To be absolutely sure you have it right, construct an absolute path using __DIR__ or the DOCUMENT_ROOT. include __DIR__ . "/../config.php"; include $_SERVER["DOCUMENT_ROOT"] . "/Directory/config.php"; Quote Link to comment https://forums.phpfreaks.com/topic/310529-how-to-include-files-from-a-parent-directory/#findComment-1576715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.