0

On my new webserver it seems that the __FILE__ constant doesn't work properly.

If I open a file containing: <? echo (__FILE__); ?> under the adresse of http://www.nico-webdesign.de/test.php it returns me /homepages/40/d467088061/htdocs/nicowebdesign/test.php.

Can that be right?

nik
  • 2,114
  • 3
  • 22
  • 43
  • It most certainly is right :-). `__FILE__` expands to the file system path of the file it is contained in, not the URL you accessed it with. – Tom Regner May 03 '13 at 11:51

1 Answers1

0

Yes, that appears to be right.

__FILE__ is a constant containing the full pathname to the file it is used in.

Your question states that the path returned is "wrong". What path should __FILE__ return according to you? Keep symlinks in mind: __FILE__ returns the full, real, non-symlinked path, even if you used a symlink to go to that path and created that file.

See: http://php.net/manual/en/language.constants.predefined.php

Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved

If you would like the URL used to access the file from the browser, see: Get the full URL in PHP

Community
  • 1
  • 1
Toby Hinloopen
  • 186
  • 1
  • 7