Robert
Robert

Reputation: 101

Move up on folder from absolute path

How do I accomplish to move up one folder from absolute path?

File structure:

/folder/
/folder/config.php
/folder/classes/test.php

From test.php I want to include_once or require_once the config.php -file.

I've tried this in test.php, but it doesn't work:

require_once(dirname(__FILE__) . '/../config.php');

Error message: *PHP Fatal error: require_once(): Failed opening required '/loooong-path/classes/../test.php'*

Upvotes: 6

Views: 9281

Answers (4)

DaGhostman Dimitrov
DaGhostman Dimitrov

Reputation: 1626

you could try:

require_once(realpath(__DIR__ . '/../config.php'));

Not tested but in theory it is supposed to work.

Upvotes: 9

Venkat Kotra
Venkat Kotra

Reputation: 10743

require_once(dirname(__FILE__) . '/../config.php');

Upvotes: 0

Davide Berra
Davide Berra

Reputation: 6568

Why not just

require_once('../config.php');

Upvotes: 2

Prasanth Bendra
Prasanth Bendra

Reputation: 32720

Try this :

require_once(dirname(__FILE__).'../config.php');

Upvotes: 0

Related Questions