简体   繁体   中英

Factors effecting __DIR__ in PHP

I was migrating a server and causes issues with DIR in PHP. I am not a developer.

The values of DIR in two servers was different. I have created a test.php file in both the server as

<?php
echo 'DIR:' .__DIR__;
?>

in the directory /var/www-beta/. But one Output shows as DIR:/var/xxx.yyy.com/releases/20130917190718/webroot and other shows as /var/www-beta/ . How to get same value in both the server?

Update : Still cannot find out the solution

From php DIR
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname( FILE ). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)

This is the way the function works. The rest is you being confused about which folder you are in.

_ DIR _ is Magic constant that returns current directory location which may be different for both servers.

first check document root using following code in both server

echo $_SERVER['DOCUMENT_ROOT'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM