ShaolinF Posted December 7, 2009 Share Posted December 7, 2009 Hi Guys I am trying to add a file which is located one dir above the current file dir. I do the following to includet the file: require_once('../myfile.php'); However this gives me a 'no such file or dir' error. Any ideas on where Im going wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/184327-including-files-in-different-dirs/ Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 Well some stupid things to test, A make sure that file is there, you can do a simple check with a test script using file_exists you can also print the current working directory to make sure you are where you think you are with getcwd Check those items and see if anything is going fishy etc, you may find out that the current directory is not where you expected it to be, if that is the case I would use the $_SERVER['DOCUMENT_ROOT'] to define my paths to include so they are the absolute locations and not relatives (will make it more precise etc). Quote Link to comment https://forums.phpfreaks.com/topic/184327-including-files-in-different-dirs/#findComment-973129 Share on other sites More sharing options...
monkeytooth Posted December 7, 2009 Share Posted December 7, 2009 Depends on how you have your files in the directories to. If you got your main file in the root directory and your trying to include the file from the sub directory then sub/myfile.php if your main file is in a sub directory and the file you want to include is in another sub directory both off the root directory. ../sub/myfile.php sometimes if you are deeper from the root directory then one folder you need more than one ../ ../../myfile.php Quote Link to comment https://forums.phpfreaks.com/topic/184327-including-files-in-different-dirs/#findComment-973135 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.