Home > Bookmarks, PhP, Tech > PHP Current Folder – 6 Solution

PHP Current Folder – 6 Solution

February 21st, 2009 Leave a comment Go to comments

using getcwd (Gets the current working directory)

$current_directory = getcwd();

using dirname (Returns directory name component of path)

$current_directory = dirname(__FILE__); <=== The Fastest
or
$current_directory = dirname($_SERVER["SCRIPT_FILENAME"]);
or
$current_directory = dirname( $_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"] );

using substr (Return part of a string) and strrpos (Find position of first occurrence of a string)

$current_directory = substr(__FILE__, 0, strrpos(__FILE__, "\\"));

or

$current_directory = substr( $_SERVER["SCRIPT_FILENAME"], 0, strrpos( $_SERVER["SCRIPT_FILENAME"], "/" ) );

  1. No comments yet.
  1. No trackbacks yet.
GoCache - ByREV-Cache v1.0 - live served in : 0.184084 sec (gzip)