(PHP 4, PHP 5, PHP 7)

chdirChange directory


chdir ( string $directory ) : bool

Changes PHP's current directory to directory.



The new current directory

Valorile întoarse

Întoarce valoarea TRUE în cazul succesului sau FALSE în cazul eșecului.


Throws an error of level E_WARNING on failure.


Example #1 chdir() example


// current directory
echo getcwd() . "\n";


// current directory
echo getcwd() . "\n";


Exemplul de mai sus va afișa ceva similar cu:



Notă: Când este activat modul securizat , PHP verifică dacă directorul în care doriți să operați are același UID (proprietar) ca și script-ul care se execută.


If the PHP interpreter has been built with ZTS (Zend Thread Safety) enabled, any changes to the current directory made through chdir() will be invisible to the operating system. All built-in PHP functions will still respect the change in current directory; but external library functions called using FFI will not. You can tell whether your copy of PHP was built with ZTS enabled using php -i or the built-in constant PHP_ZTS.

A se vedea și

  • getcwd() - Gets the current working directory

add a note add a note

User Contributed Notes 2 notes

php dot duke at qik dot nl
11 years ago
When changing dir's under windows environments:

/* getcwd() gives you back "c:\temp" */

/* getcwd() gives you back "c:\temp\" */

to work around this inconsistency
doing a chdir('.') after the chdir always gives back "c:\temp"
herwin at snt dot utwente dot nl
13 years ago
When using PHP safe mode and trying to change to a dir that is not accessible due to the safe mode restrictions, the function simply fails without generating any kind of error message.

(Tested in PHP 4.3.10-16, Debian Sarge default)
To Top