Home >Backend Development >PHP Tutorial >目录管理函数库_PHP

目录管理函数库_PHP

WBOY
WBOYOriginal
2016-06-01 12:38:401029browse

兼容:(PHP 3, PHP 4, PHP 5)
chdir -- 改变目录
语法:bool chdir ( string directory )
返回值:整数
函数种类: 文件存取

内容说明:
将 PHP 的当前目录改为directory。directory:新的当前目录。返回值如果成功则返回 TRUE,失败则返回 FALSE。


例子讲解:
<font color="#000000"> <font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br></font><font color="#FF8000">// current directory<br><br></font><font color="#007700">echo </font><font color="#0000BB">getcwd</font><font color="#007700">() . </font><font color="#DD0000">"\n\";<br><br>chdir('public_html');<br><br>// current directory<br><br>echo getcwd() . \"\n\";<br><br>?></font> </font>
<font color="#000000"> <font color="#0000BB">输出结果为:<br><br></font><font color="#007700">/</font><font color="#0000BB">home</font><font color="#007700">/</font><font color="#0000BB">vincent <br><br></font><font color="#007700">/</font><font color="#0000BB">home</font><font color="#007700">/</font><font color="#0000BB">vincent</font><font color="#007700">/</font><font color="#0000BB">public_html</font> </font>  

注意:循环语句中会出现“ Warning: chdir(): No such file or directory (errno 2) in ***** on line *”错误。
<font color="#000000"> <font color="#0000BB"></font><font color="#007700"></font><font color="#0000BB">php<br><br></font><font color="#FF8000">// current directory<br><br></font><font color="#007700">echo </font><font color="#0000BB">getcwd</font><font color="#007700">() . </font><font color="#DD0000">"\n\";<br><br>for($i=1; $i<br>    chdir('whoist');<br><br>// current directory<br><br>echo getcwd() . \"\n\";<br><br>}<br><br>?></font> </font>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn