chdir()
(PHP 4, PHP 5, PHP 7)
改变目录
说明
chdir(string $directory): bool
将 PHP 的当前目录改为$directory。
参数
- $directory
新的当前目录
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。
错误/异常
Throws an error of levelE_WARNING
on failure.
范例
Example #1chdir()例子
<?php // current directory echo getcwd() . "\n"; chdir('public_html'); // current directory echo getcwd() . "\n"; ?>
以上例程的输出类似于:
/home/vincent /home/vincent/public_html
注释
Note:当启用安全模式时,PHP 会在执行脚本时检查被脚本操作的目录是否与被执行的脚本有相同的 UID(所有者)。
参见
getcwd()
取得当前工作目录
When changing dir's under windows environments: <?php $path="c:\temp"'; chdir($path); /* getcwd() gives you back "c:\temp" */ $path="c:\temp\"'; chdir($path); /* getcwd() gives you back "c:\temp\" */ ?> to work around this inconsistency doing a chdir('.') after the chdir always gives back "c:\temp"
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)