Every PHP script process has its own current working directory, files and directory are created under this directory by default if not otherwise specified.
The default working directory of any php script is the home directory of the php owner or the current working directory returned by Linux shell command pwd. As most of the time, PHP scripts are run from the Web, if not otherwise specified, the current working directory would be the home directory of the user.
However, you can always change the current working directory in PHP itself. The function needed is chdir(). For example,
changes the current working directory to ‘/home/john/temp’. And after this in the same php script,
changes the working directory to ‘/home/john/temp/0845’. It’s just like traversing the file structure under Linux.
1 thought on “PHP: Change Current Working Directory”
Pingback: PHP: Make or Create A Directory
Comments are closed.