dir
Description
Return an instance of the Directory class
Syntax
dir(string $directory, ?resource $context = null): Directory|false
Parameters
directory
Directory to open
context
A context stream resource.
Return
Returns an instance of Directory, or false in case of error.
Examples
1 · directory
<? $directory = "."; $return = dir($directory); print_r($return); ?>
Directory Object ( [path] => . [handle] => Resource id #3 )
2 · context
<? $directory = "."; $context = stream_context_create(); $return = dir($directory, $context); print_r($return); ?>
Directory Object ( [path] => . [handle] => Resource id #3 )
3 · read
<? $directory = "."; $return = dir($directory); echo "path: $return->path\n"; echo "handle: $return->handle\n\n"; while(($read = $return->read()) !== false) { echo "$read\n"; } $return->close(); ?>
path: . handle: Resource id #3 index.php simpletext.xbm red_crop_trans.png simpletext.jpg dashedline.png php.webp .. simple.gd stringup.png imagecolortransparent.png red_300.png paletteimage.png imagefilledrectangle.png simple.gd2 . simpletext.wbmp phplogo.jpg file.png imageline.png php.bmp