Jump to content

Including php files


jeremywilms

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.