opendir

Open directory handle

&reftitle.description; ``resource``false```opendir` `string` `directory` ``resource``null```context`&null;

Opens up a directory handle to be used in subsequent `closedir`, `readdir`, and `rewinddir` calls.

&reftitle.parameters;

`directory`

- The directory path that is to be opened

`context`

- For a description of the `context` parameter, refer to the streams section of the manual.

&reftitle.returnvalues;

Returns a directory handle `resource` on success, &return.falseforfailure;

&reftitle.errors; &fs.emits.warning.on.failure;

This may happen if `directory` is not a valid directory, the directory can not be opened due to permission restrictions, or due to filesystem errors.

&reftitle.changelog;

&Version; | &Description;
8.0.0 | `context` is now nullable.

&reftitle.examples;

### `opendir` example

    <?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);
        }
    }
    ?>

&example.outputs.similar;

    filename: . : filetype: dir
    filename: .. : filetype: dir
    filename: apache : filetype: dir
    filename: cgi : filetype: dir
    filename: cli : filetype: dir

&reftitle.seealso;

- `is_dir`
- `readdir`
- `dir`