Php opendir open directory function

Source: Internet
Author: User
Tags php error

Php opendir open directory function

PHP 4, PHP 5)

Opendir-Open Directory handle

Report error description
Resource opendir (string $ path [, resource $ background])
A directory handle is opened for subsequent closedir (), readdir (), and rewinddir () calls.

Definition and usage
The opendir () function opens a directory handle, which can be used by closedir (), readdir (), and rewinddir.

If the operation succeeds, the function returns a directory stream. Otherwise, false and an error are returned. You can add "@" before the function name to hide the error output.


Report error parameters

Path
The directory path is to open

Context
For context parameter descriptions, see the flow section in the manual.

<? Php
$ Dir = "/etc/php5 /";

// Open a known directory, and proceed to read its contents
If (is_dir ($ dir )){
If ($ dh = opendir ($ dir )){
While ($ file = readdir ($ dh ))! = False ){
Echo "filename: $ file: filetype:". filetype ($ dir. $ file). "n ";
        }
Closedir ($ dh );
    }
}
?>
The above example will output something similar:

Filename:.: filetype: dir
Filename: ..: filetype: dir
Filename: apache: filetype: dir
Filename: cgi: filetype: dir
Filename: cli: filetype: dir

 

Report error return value
Returns the success or FALSE of the failed resource of the directory handle.

If the path is not a valid directory or the directory cannot be opened, opendir () returns FALSE due to permission restrictions or file system errors, and generates an E_WARNING-level PHP error. You can suppress adding the '@' function name before the opendir error output.

Report error update log

Version description
5.0.0 supports the ftp: // URL protocol.
The 4.3.0 path can also be any URL that supports the directory list, but only the File: // URL protocol supports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.