开发者

Including files issue with relative paths on a linux system

开发者 https://www.devze.com 2023-01-16 07:54 出处:网络
I have the following directory tree structure: /index.php /code/inc/variables.php /code/inc/config.php index.php is the file that is called.

I have the following directory tree structure:

/index.php
/code/inc/variables.php
/code/inc/config.php

index.php is the file that is called.

On our development system in: /code/inc/variables.php, when 开发者_开发技巧I have the line:

require_once("./code/inc/config.php");

it doesnt work and when I have:

include_once('config.php');

it does work.

The puzzle is that the first works on our development system and the second works on our production system. And there is no difference in the tree structure on either of the two systems (both run linux, different versions perhaps).


If you call require_once in file DOCUMENT_ROOT/public_html/x.php:

require_once("./code/inc/config.php");

that's meen what it will be searched for file

DOCUMENT_ROOT/public_html/code/inc/config.php

if you call same require_once DOCUMENT_ROOT/public_html/code/inc/variables.php:

it will be searching for file:

DOCUMENT_ROOT/public_html/code/inc/code/inc/config.php

and of course it fails.

You can use request like this:

require_once($_SERVER['DOCUMENT_ROOT'] . "/code/inc/config.php");

and it will work in all your files correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号