user393273
user393273

Reputation: 1438

include .php file in folder above

I am receiving this error

Warning: include(../config.php) [function.include]: failed to open stream: No such file or directory in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 2

Warning: include() [function.include]: Failed opening '../config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 2

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'soizastu'@'localhost' (using password: NO) in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 6
Error connecting to database.

basically in the cms folder is config.php i thought include "../config.php"; would do the trick but it dosent appear so.

Upvotes: 10

Views: 20811

Answers (5)

Sivabharathy
Sivabharathy

Reputation: 1

Try this code i hope it works for me

Assume we had dbconfig.php in home directory and include that file in file that inside home like path structure. |--admin |--includes |--add_dbconfig.php |--dbconfig.php

add_dbconfig.php

enter image description hereenter image description here

Upvotes: 0

Habib Rosyad
Habib Rosyad

Reputation: 342

Just define the absolute path for the cms folder, in this case if the caller script (which you try to include the config.php) /home/soizastu/public_html/cms/happy-api/retrieve.php. Then write on top line of retrieve.php :

define('ABSPATH',dirname(dirname(__FILE__)) . '/');

and include the config.php by write :

require(ABSPATH . 'config.php');

Upvotes: 0

Sam Bisbee
Sam Bisbee

Reputation: 4441

Make sure that the user you're using to run your web server can read the file. For a sanity check, chmod the file to 665. If it's a Windows system, then make it so that Everyone can read the file.

Upvotes: 1

Alin P.
Alin P.

Reputation: 44346

Try computing the absolute path and including that.

include(dirname(__FILE__)."/../config.php");

I think it's the safest bet when dealing with multiple levels of include.

Upvotes: 37

Malachi
Malachi

Reputation: 33690

This should work include('../config.php');

Upvotes: 0

Related Questions