schilly Posted August 21, 2009 Share Posted August 21, 2009 Ok weird situation here. Here is my file structure: admin -->index.php -->modules/ -->mymodule/ -->index.php -->includes/ -->views/ So everyone is loaded off the admin index.php page and it includes different modules depending on the variables provided. So here's the problem. I'm trying to include a file in includes from a file in views and include("../includes/include.php"); wont work. If I include from the mymodule index.php (includes/includes.php) it works but the include file is all html so I didn't want to have to wrap it in a variable to use it in the views/ script. So I ended up doing some debug and found the executing directory to actually be the admin directory which makes sense because that's where the original request is coming from. Switch my include to (modules/mymodule/includes/includes.php) and it works. Now here's my question. Why would includes/includes.php work in the mymodule index but the ../includes/includes.php not work in the views/ page? Is there something about the file system that breaks when you try to go backwards in a directory? Hopefully this I made this clear. Thanks. Link to comment https://forums.phpfreaks.com/topic/171352-solved-includes-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2009 Share Posted August 21, 2009 Relative include paths (those with ../ or ./) are relative to the current working directory (CWD). The starting CWD is that of the main script file that is including all the other files, not a file that has already been included at a path different than the main script file and wants to include yet another file. You can either use absolute file system paths, form more complicated relative paths ../../, change the CWD (and remember to change it back as necessary), or setup and use the include_path and let php search for the files to include (slower than if you don't use the include_path.) Link to comment https://forums.phpfreaks.com/topic/171352-solved-includes-question/#findComment-903661 Share on other sites More sharing options...
schilly Posted August 21, 2009 Author Share Posted August 21, 2009 Awesome thanks. Make sense for the ../ and ./ now. Link to comment https://forums.phpfreaks.com/topic/171352-solved-includes-question/#findComment-903693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.