chdir -- 改变目录
语法:bool chdir ( string directory )
返回值:整数
函数种类: 文件存取
内容说明:
将 PHP 的当前目录改为directory。directory:新的当前目录。返回值如果成功则返回 TRUE,失败则返回 FALSE。
例子讲解:
<?php
// current directory
echo getcwd() . "\n";
chdir('public_html');
// current directory
echo getcwd() . "\n";
?>
输出结果为:
/home/vincent
/home/vincent/public_html
注意:循环语句中会出现“ Warning: chdir(): No such file or directory (errno 2) in ***** on line *”错误。 www.444p.com
<?php
// current directory
echo getcwd() . "\n";
for($i=1; $i<=2; $i++){
chdir('whoist');
// current directory
echo getcwd() . "\n";
}
?>