HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

dir

Description

The dir of Directory for PHP returns 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);
Array
(
    [0] => /etc/alternatives
    [1] => /etc/apache2
    [2] => /etc/bash_completion.d
    [3] => /etc/cl.nodejs
    [4] => /etc/cl.php.d
    [5] => /etc/cl.python
    [6] => /etc/cl.selector
    [7] => /etc/cl.selector.conf.d
    [8] => /etc/cpanel
    [9] => /etc/crypto-policies
    [10] => /etc/default
    [11] => /etc/environment-modules
    [12] => /etc/fonts
    [13] => /etc/gcrypt
    [14] => /etc/imunify360
    [15] => /etc/joe
    [16] => /etc/ld.so.conf.d
    [17] => /etc/mail
    [18] => /etc/mc
    [19] => /etc/modulefiles
    [20] => /etc/motd.d
    [21] => /etc/my.cnf.d
    [22] => /etc/openldap
    [23] => /etc/pam.d
    [24] => /etc/pki
    [25] => /etc/profile.d
    [26] => /etc/sasl2
    [27] => /etc/scl
    [28] => /etc/security
    [29] => /etc/skel
    [30] => /etc/ssh
    [31] => /etc/ssl
    [32] => /etc/sysconfig
)

2 · context

<?

$directory = ".";
$context = stream_context_create();

$return = dir($directory, $context);

print_r($return);
false

3 · read

<?

$directory = ".";

$return = dir($directory);

echo "path: $return->path\n"
. "handle: $return->handle\n\n";

while(($read = $return->read()) !== false)
{
    echo "$read\n";
}
$return->close();
path: .
handle: Resource id #3

127.0.0.1
.
..
index.php
my.sock