Bman900 Posted June 27, 2009 Share Posted June 27, 2009 include('./file.php'); or include('../file.php'); I have to scripts that both use the include function. 1. root/pandora/include/contants.php which includes <?php include ("./include.php"); ?> Than I have root/demo/admin/admin.php which includes <?php include("../include/session.php"); include("../include.php"); include("../config.php"); ?> In both of those scripts I need to go back one folder. In the first one it only work with one . while in the other one it only work with two . Here are the errors I get: First script if I add the two dots: Warning: include(../include.php) [function.include]: failed to open stream: No such file or directory in /home/balint/public_html/pandora/include/constants.php on line 2 Warning: include() [function.include]: Failed opening '../include.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/balint/public_html/pandora/include/constants.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/balint/public_html/pandora/include/constants.php:2) in /home/balint/public_html/pandora/include/session.php on line 50 Code at line 2: <?php include ("../include.php"); ?> Second script if I have only one dot errors: Warning: include(./include/session.php) [function.include]: failed to open stream: No such file or directory in /home/balint/public_html/demo/admin/admin.php on line 3 Warning: include() [function.include]: Failed opening './include/session.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/balint/public_html/demo/admin/admin.php on line 3 Warning: include(./include.php) [function.include]: failed to open stream: No such file or directory in /home/balint/public_html/demo/admin/admin.php on line 4 Warning: include() [function.include]: Failed opening './include.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/balint/public_html/demo/admin/admin.php on line 4 Warning: include(./config.php) [function.include]: failed to open stream: No such file or directory in /home/balint/public_html/demo/admin/admin.php on line 5 Warning: include() [function.include]: Failed opening './config.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/balint/public_html/demo/admin/admin.php on line 5 And to clarify here is the code on those line: <?php session_start(); include("./include/session.php"); include("./include.php"); include("./config.php"); ?> Any ideas why this behavior is happening? Quote Link to comment Share on other sites More sharing options...
chmpdog Posted June 27, 2009 Share Posted June 27, 2009 hmm.. try three dots? Quote Link to comment Share on other sites More sharing options...
Bman900 Posted June 27, 2009 Author Share Posted June 27, 2009 Yes I actually tried four dots, nothing is working........... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2009 Share Posted June 27, 2009 From the php.net documentation for the include() function - If filename begins with ./ or ../, it is looked for only in the current working directory or parent of the current working directory, respectively. One dot refers to the current working directory (which is not necessarily the current directory if you have more than one level of include statements.) Two dots refer the parent of the current working directory. Only none, one, or two dots have any meaning in file system paths. The default current working directory is that of the main script that was requested. If the main script includes a file that is in some other folder than the main script and that file then includes another file, the last include is relative to the folder that the main file is in. You may in fact find that using absolute file system paths, formed using - $_SERVER['DOCUMENT_ROOT'] . '/actual_path/your_file.php' eliminates all ambiguity about where a file is being included from. Quote Link to comment Share on other sites More sharing options...
Bman900 Posted June 27, 2009 Author Share Posted June 27, 2009 See I thought about that but if I create scripts later on I want them to be placed any where on a server and not just a folder I require. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2009 Share Posted June 27, 2009 Then you should leave all the ./ and ../ off and use the include_path setting and let php search the include_path to find the files. Quote Link to comment Share on other sites More sharing options...
Bman900 Posted June 27, 2009 Author Share Posted June 27, 2009 I tried to search for include_path setting in my php.ini and no luck. Quote Link to comment Share on other sites More sharing options...
trq Posted June 27, 2009 Share Posted June 27, 2009 I tried to search for include_path setting in my php.ini and no luck. Then your php.ini is missing directives. Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted June 27, 2009 Share Posted June 27, 2009 Try the entire path. Then it will work in all cases and all directories.. <?php include("/root/pandora/include/session.php"); ?> You may also want to look into "require once" as in some cases you need to make sure the file is there. If not then don't even bother with the rest of the page. Quote Link to comment 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.