PHP

ABSOLUTE RELATIVE PATH IN PHP

ABSOLUTE PATH - FULL FILE PATH require "D:\\HTTP\\LIB\\SCRIPT.PHP";

RELATIVE ABSOLUTE PATH

01

RELATIVE PATH - BASED ON CURRENT WORKING DIRECTORY require "LIB/SCRIPT.PHP";

CURRENT WORKING DIRECTORY IS THE FOLDER OF THE CURRENT SCRIPT. E.G. IF THIS SCRIPT IS PLACED IN D:\HTTP\ echo getcwd(); D:\HTTP\

WORKING DIRECTORY

02

THIS IS D:\HTTP\A.PHP require "LIB/B.PHP";   THIS IS D:\HTTP\LIB\B.PHP echo getcwd();

WORKING DIRECTORY

03

WHEN WE RUN A.PHP - GETCWD() WILL SHOW D:\HTTP\.    THE WORKING DIRECTORY IS FIXED TO THE FIRST SCRIPT THAT RUNS!

CHANGE WORKING DIRECTORY chdir("D:\\HTTP\\"); MAGIC CONSTANTS echo __FILE__; CURRENT SCRIPT echo __DIR__; CURRENT FOLDER

MORE PATH YOGA

04

SERVER DOCUMENT ROOT echo $_SERVER["DOCUMENT_ROOT"];  CURRENT RUNNING SCRIPT echo $_SERVER["PHP_SELF"]; CURRENT SCRIPT PATH echo $_SERVER["SCRIPT_FILENAME"];