Jump to content

include_once problems


Mr.n

Recommended Posts

Dear all,

 

I am facing a problems with a php script, i receive the following error however the same code that produce an error here is working fine in another script.

 

Warning: include_once(./***/*.php): failed to open stream: No such file or directory in /******/******.php on line 107

 

Warning: include_once(): Failed opening './***/*.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /*****/init.php on line 107

 

Fatal error: Call to undefined function dba_connect() in /*****/*****/init.php on line 110

 

I would like to know if it's a file permission issue because all the files exist. Also i didn't understand this error related to pear, can someone advice please

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/154253-include_once-problems/
Share on other sites

let me guess, the scripts are located in different folders?

 

what is the folder structure of everything?

 

in your scripts, you can call the included files with the relative paths cus you know where you are:

include_once('./includes/foobar.php');

 

but, in the include file (aka foobar.php) if you include any files, you can't use relative paths. this is because it's relative to the calling script, not the include...so basically you don't know where you are. a good workaround is to use:

include_once(dirname(__FILE__).'/path/relative/to/include/file.php');

__FILE__ will give you the full path to the file where that piece of code is (aka the include file)...dirname() then gets you the folder that the include file is in, and now you know where you are and can build from there

 

does that makes sense?

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.