PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<getcwdreaddir>
Last updated: Mon, 16 Jul 2012

opendir

(PHP 3, PHP 4, PHP 5)

opendir -- 打开目录句柄

说明

resource opendir ( string path )

返回一个目录句柄,可以在之后用在 closedir()readdir()rewinddir() 调用中。

如果 path 不是一个合法的目录或者因为权限限制或文件系统错误而不能打开目录,opendir() 返回 FALSE 并产生一个 E_WARNING 级别的 PHP 错误信息。可以在 opendir() 前面加上“@”符号来抑制错误信息的输出。

例子 1. opendir() 例子

<?php
$dir
= "/tmp/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
   if (
$dh = opendir($dir)) {
       while ((
$file = readdir($dh)) !== false) {
           print
"filename: $file : filetype: " . filetype($dir . $file) . "\n";
       }
      
closedir($dh);
   }
}
?>

PHP 4.3.0path 也可以是任何支持目录列表的 URL,但是在 PHP 4.3 中只支持 file:// url 协议。自 PHP 5.0.0 起,也包括了 ftp:// url 协议的支持。

参见 is_dir()readdir()Dir




<getcwdreaddir>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST