doubledee Posted August 7, 2011 Share Posted August 7, 2011 What is the best way to get the File Path and File Name of the currently running script in PHP? I have read that $_SERVER['PHP_SELF'] is not safe or reliable?! Debbie Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/ Share on other sites More sharing options...
trq Posted August 7, 2011 Share Posted August 7, 2011 Use the constants __FILE__ and __DIR__ Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253597 Share on other sites More sharing options...
doubledee Posted August 7, 2011 Author Share Posted August 7, 2011 Use the constants __FILE__ and __DIR__ The manual says "The full path and filename of the file." Does this mean the file name and path to the "Document Root"?? Debbie Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253602 Share on other sites More sharing options...
trq Posted August 7, 2011 Share Posted August 7, 2011 No. As the manual says, it means the full path to the file. And the name of the file. Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253604 Share on other sites More sharing options...
doubledee Posted August 7, 2011 Author Share Posted August 7, 2011 No. As the manual says, it means the full path to the file. And the name of the file. I'm not getting what "the full path" is?! I am trying to get the path (including script name) from my WEB ROOT. (As opposed to the FILE ROOT.) Debbie Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253747 Share on other sites More sharing options...
Pikachu2000 Posted August 7, 2011 Share Posted August 7, 2011 http://www.php.net/manual/en/reserved.variables.server.php Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253751 Share on other sites More sharing options...
doubledee Posted August 7, 2011 Author Share Posted August 7, 2011 http://www.php.net/manual/en/reserved.variables.server.php That link says *deprecated* And I already looked at the manual - as noted above - and said I was confused. Debbie Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253753 Share on other sites More sharing options...
Pikachu2000 Posted August 7, 2011 Share Posted August 7, 2011 If all you saw was "deprecated", you must not have read past the second line. It says: $_SERVER $HTTP_SERVER_VARS [deprecated] $_SERVER is not deprecated, $HTTP_SERVER_VARS is. Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253844 Share on other sites More sharing options...
jcbones Posted August 8, 2011 Share Posted August 8, 2011 When I question what something does, I follow the age old de-bugging rule. When in doubt, echo it out! Link to comment https://forums.phpfreaks.com/topic/244094-best-way-to-get-current-path-and-filename/#findComment-1253952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.