Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'*

like image 806
Robert Avatar asked Mar 06 '13 12:03

Robert


People also ask

How do I change directory in absolute path?

To change directories using absolute pathnames, type cd /directory/directory; to change directories using relative pathnames, type cd directory to move one directory below, cd directory/directory to move two directories below, etc.; to jump from anywhere on the filesystem to your login directory, type cd; to change to ...

What is an absolute folder?

An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders. An absolute path is also known as an absolute pathname or full path.


1 Answers

you could try:

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

Not tested but in theory it is supposed to work.

like image 124
DaGhostman Dimitrov Avatar answered Sep 22 '22 12:09

DaGhostman Dimitrov