PHP: Change Current Working Directory

by Yang Yang on April 22, 2009

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,

chdir('/home/john/temp');

changes the current working directory to ‘/home/john/temp’. And after this in the same php script,

chdir('0845');

changes the working directory to ‘/home/john/temp/0845′. It’s just like traversing the file structure under Linux.

Subscribe to Kavoir: blog feed

You should also read:

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: