<?php
$p = getcwd();
echo $p;
?>
Ans: getcwd()
Here I have stored my files under httdocs (using php5,i haven't checked under php4) so I get the output as C:\apache2triad\htdocs
you may get your path information while runnings the above code. :)
$_SERVER['DOCUMENT_ROOT']
$_SERVER['DOCUMENT_ROOT'] returns the file system path to your root directory
or why not use the magic
or why not use the magic constant __FILE__?
$doc_root = dirname(__FILE__);
?>
we can use
we can use $_SERVER['DOCUMENT_ROOT'] for getting absolute path, but what was asked in the question is the FUNCTION in php to get the absolute path so getcwd() is the ans
we can't use
we can use $_SERVER['DOCUMENT_ROOT'] for getting absolute path, because it gives path only up to document root
for eg:
suppose your file is in C:/wamp/www/sample
$_SERVER['DOCUMENT_ROOT'] will give only C:/wamp/www/
but getcwd() will give C:/wamp/www/sample
Why do not use
Why do not use $_SERVER['DOCUMENT_ROOT'] for getting absolute path>
Post new comment