jeremywilms Posted January 23, 2010 Share Posted January 23, 2010 I'm having trouble with including files in php. Consider I have a.php located in root/a/a/a b.php located in root/a/a/b c.php located in root/b/a/a I know it's confusing, but this problem is a pretty stupid one.. consider a.php includes b.php via include_once("./b/b.php"); and c.php includes a.php via include_once("./././a/a/a.php); Now, I'm pretty sure php includes just by replacing the include statement with the contents of the include file. Here's the problem. If c.php includes a.php, which includes b.php using a path relative to a.php's location, it will not work if it's included using a path relative to c.php. Which I believe is happening in my situation. Maybe I'm wrong, maybe not. I'm just writing a couple modules for a friend. I work with C++, where include files include relative to their location, and not the includers location. So forgive me if this is a dumb question. And sorry if it's hard to understand, I don't know how to explain it really. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/ Share on other sites More sharing options...
DJCMBear Posted January 23, 2010 Share Posted January 23, 2010 You would have to use '../' to come out of the folder you are in. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000360 Share on other sites More sharing options...
jeremywilms Posted January 23, 2010 Author Share Posted January 23, 2010 What's the difference between './' and '../' ? If a.php is in root/a/ and b.php in root/b/ If I include b.php in a.php via require_once("./b/b.php"); it works, but if I go: require_once("../b/b.php"); //Notice the '../' I get Warning: require_once(../b/b.php) [function.require-once]: failed to open stream: No such file or directory in root/a/a.php on line 3 Strange. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000363 Share on other sites More sharing options...
jeremywilms Posted January 23, 2010 Author Share Posted January 23, 2010 Wait just a second, I'll upload an example you can extract to a local server if you have one setup. It'll be easier to understand what I'm trying to say. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000365 Share on other sites More sharing options...
jeremywilms Posted January 23, 2010 Author Share Posted January 23, 2010 Here, extract this to a local server which supports php. Then visit the page problem1/c/d/d.php Warning: require_once(../b/b.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\example\problem1\a\a.php on line 3 Fatal error: require_once() [function.require]: Failed opening required '../b/b.inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\example\problem1\a\a.php on line 3 [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000366 Share on other sites More sharing options...
jeremywilms Posted January 23, 2010 Author Share Posted January 23, 2010 Can someone at least download the file, I know it's hard to understand what I'm trying to say, but if you just read the comment above, you'll see what's happening.. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000539 Share on other sites More sharing options...
jeremywilms Posted January 23, 2010 Author Share Posted January 23, 2010 Problem solved: http://www.webmaster-talk.com/php-forum/196657-error-including-file-includes-another-file.html Thanks to those who replied. Link to comment https://forums.phpfreaks.com/topic/189523-including-php-files/#findComment-1000589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.