简体   繁体   中英

Isses with __DIR__ PHP code implementing the wrong home directory

My home directory path is /home9/ but when I using the __DIR__ code to get the path, I get /home/ it's missing the number 9 , I know I can get the path by using $_SERVER['DOCUMENT_ROOT'] , I just want to know why and how to fix it, I really need to use the __DIR__ code.

<?php
// this is the first code
echo __DIR__ .'<br>'; //I get /home/username/public_html/ is the wrog path

// this the secound code
echo $_SERVER['DOCUMENT_ROOT']; //I get /home9/username/public_html/ the correct path
?>

I contacted my hosting provider and they couldn't help, please help.

These are 2 different things.

Here in your case /home9/username/public_html/ is symlinked to /home/username/public_html/ where /home9/username/public_html/ is the actual document root. However __DIR__ returns the real path where symlink resolves to.

You can refer php documentation for more information in between these 2.

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