Directory 实例是通过调用 dir() 函数创建的,而不是 new 操作符
Directory { /* 属性 */ public string $path ; public resource $handle ; /* 方法 */ public void close ([ resource $dir_handle ] ) public string read ([ resource $dir_handle ] ) public void rewind ([ resource $dir_handle ] ) }
bool chdir ( string $directory )
参数:directory:
新的当前目录————将 PHP 的当前目录改为 directory
。
返回值:成功时返回 TRUE
, 或者在失败时返回 FALSE
。
Example #1 chdir() 例子
<?php // current directory echo getcwd() . "\n"; chdir(‘public_html‘); // current directory echo getcwd() . "\n"; ?>
以上例程的输出类似于:
/home/vincent
/home/vincent/public_html
注:chdir中的目录参数必须是getcwd()目录下面的子目录。否则出现警告:
Warning: chdir(): No such file or directory (errno 2) in C:\AppServ\www\test2.php on line 6
bool chroot ( string $directory )
参数:
directory
新目录
将当前进程的根目录改变为 directory
。
本函数仅在系统支持且运行于 CLI,CGI 或嵌入 SAPI 版本时才能正确工作。此外本函数还需要 root 权限。
返回值:成功时返回 TRUE
, 或者在失败时返回 FALSE
。
Example #1 chroot() example
<?php chroot("/path/to/your/chroot/"); echo getcwd(); ?>
以上例程会输出:/
实际上会警告:
Fatal error: Call to undefined function chroot() in C:\AppServ\www\test.php on line 2
注释:Note: 此函数未在 Windows 平台下实现。
void closedir ([ resource $dir_handle ] )
关闭由 dir_handle
指定的目录流。流必须之前被 opendir() 所打开。
dir_handle
目录句柄的 resource,之前由 opendir() 所打开的。如果目录句柄没有指定,那么会假定为是opendir()所打开的最后一个句柄。<?php $dir = "/etc/php5/"; // Open a known directory, read directory into variable and then close if (is_dir($dir)) { if ($dh = opendir($dir)) { $directory = readdir($dh); closedir($dh); } } ?>
Directory dir ( string $directory [, resource $context ] )
以面向对象的方式访问目录。打开 directory
参数指定的目录。
参数:directory
被打开的目录
context
Note: 在 PHP 5.0.0 中增加了对上下文(Context)的支持。有关上下文(Context)的说明参见 Streams。
string getcwd ( void )
取得当前工作目录。
返回值
成功则返回当前工作目录,失败返回 FALSE
。
在某些 Unix 的变种下,如果任何父目录没有设定可读或搜索模式,即使当前目录设定了,getcwd() 还是会返回FALSE
。有关模式与权限的更多信息见 chmod()。
<?php // current directory echo getcwd() . "\n"; chdir(‘cvs‘); // current directory echo getcwd() . "\n"; ?>
输出结果:
/home/didou
/home/didou/cvs
原文:http://www.cnblogs.com/gengyi/p/6445476.html