simon551 Posted August 17, 2007 Share Posted August 17, 2007 Hi, I have a file that includes another file which contains some query information. The query info file needs to include the connections file. This is fine if I keep my site in a two-tiered schema: root/folders -- I just use '../folder/filename.php in every path. But I get confused if I try to organize anything in subfolders. I've avoided using subfolders for the most part for this reason, but the site is getting big enough that I think I'm going to have to start. for example: I have a file that references a source file so I keep the source files in a folder called sources. now I want to create a subfolder called sources because the main sources folder is too big and cumbersome. file: report1.php path: ../reports/report1.php source path: ../reports/sources/report1_source.php connection path: ../connections/conn.php then in the source file I include the connection file: require_once('../../connections/conn.php'); which is fine with that file (the report source file) but then when that file gets included down path, the path no longer works: Warning: require_once(../../connections/conn.php) [function.require-once]: failed to open stream: No such file or directory sorry if I'm not explaining this problem really well. Quote Link to comment https://forums.phpfreaks.com/topic/65526-solved-confused-about-path-of-included-file-in-included-file/ Share on other sites More sharing options...
Psycho Posted August 17, 2007 Share Posted August 17, 2007 Then don't use relative paths (i.e. the path to the file from the location of the current file). Instead use absolute paths from the root of your site. I'm having trouble following your example. But let's go with this: file: report1.php path: ../reports/report1.php source path: ../reports/sources/report1_source.php connection path: ../connections/conn.php In the file report1.php you can include the source using this: $_SERVER['DOCUMENT_ROOT'] . "/reports/sources/report1_source.php"; And that file can include the connections file using: $_SERVER['DOCUMENT_ROOT'] . "/connections/conn.php"; It doesn't matter what directory any file calls the connection file from. It will always exist at the same absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/65526-solved-confused-about-path-of-included-file-in-included-file/#findComment-327207 Share on other sites More sharing options...
simon551 Posted August 17, 2007 Author Share Posted August 17, 2007 Thanks. That is helpful. -s Quote Link to comment https://forums.phpfreaks.com/topic/65526-solved-confused-about-path-of-included-file-in-included-file/#findComment-327215 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.