PHP including files -
what's difference between
$_server['document_root'];
and
dirname(__file__);
i wonder what's difference because when 'echo' them, they're returning same path. prefer should use , why?
thanks!
both different
_file_
the full path , filename of file. if used inside include, name of included file returned. since php 4.0.2, file contains absolute path symlinks resolved whereas in older versions contained relative path under circumstances.
source : php magic constants
let's said, document /var/www
,
, index page /var/www/index.php
dirname(__file__) == $_server['document_root'];
but if drill-down sub-folder /var/www/posts/index.php
dirname(__file__) != $_server['document_root']; /var/www/posts != /var/www
the use of $_server['document_root']
more appropriate in case.
Comments
Post a Comment