Jump to content

Paths for include()


smc

Recommended Posts

Hiya,

Alright right now I'm trying to include my configuration file for a file in the admin section. The problem is that for my include file it is in the /www/ directory while the admin file is in /www/admin/. According to php.net the include function works only for the current directory the script is working in. How do I include a file from root in a script that is in /www/admin/?

Thanks for any help you can offer!!
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/
Share on other sites

Garcia I'm trying to get some in root not my current realtive directory

Thrope:

I tried your example but this is what I got:

Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23

Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23

Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23

Warning: dbconnect() [function.include]: Failed opening './config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/een/public_html/functions.php on line 23

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'een'@'localhost' (using password: NO) in /home/een/public_html/functions.php on line 24
Sorry - we could not connect to our database. Please try back later.

My guess is that this is because in functions.php I call config.php but since functions is in the same realtive path as config its just ./ as opposed to ../    Is that valid?

Thanks,
SMC
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165663
Share on other sites

Lol sorry okay here is the deal

I am working on /www/admin/file.php

file.php is trying to include /www/functions.php

functions.php is trying to include /www/config.php

Now in file.php I have it calling ../functions.php
In functions.php I have it calling ./config.php

Now I tested it when it was realtive and it worked, but here is the biggest snag:

I just tried to by taking what I needed to call from the file and dropping it right in file.php and then commenting out the include line, and it still gave me the same problem saying it couldn't execute the MySQL command.

How do I make it say the error in this scenario:

$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)
or die ("Sorry - we got lost and couldn't find the database. Please try back later.");
$rs=mysql_query($sql,$dbh)
or die ("Sorry - for whatever reason we could not execute the SQL command. Please try back later.");

Where can I drop mysql_error(); ?

Thanks!!
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165683
Share on other sites

ok lets go back to the original scenario,

in [b]functions.php[/b] change the line where it includes config.php to include it remotely like so :
[code] include "/config.php"; [/code]
and in [b]file.php[/b] change the include to look like this
[code] include "/functions.php";[/code]

this should work, fingers crossed :P
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165685
Share on other sites

Alright I think I just eliminated the include as the problem, I think I zeroed in on the wrong thing.

I just created a file in /www/ called "testroot.php" in that I declared

[code=php:0]
<?php

$apple = "orange";

?>
[/code]

Then I created /www/admin/admin_testroot.php and called

[code=php:0]
<?php

$cms_root_path = '../';
include($cms_root_path . 'testroot.php');

echo("$apple");

?>
[/code]

And it returned "orange"

Now the question is what is wrong with my SQL
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165687
Share on other sites

simple, [b]comment out[/b] the whole mysql block and add this :
[code]
$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)
or die(mysql_error());
$rs=mysql_query($sql,$dbh)
or die (mysql_error());
[/code]

showing us the errors in mysql, post back with wat it says
Link to comment
https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165690
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.