PHP - dir
Trieda
Metóda - dir
(PHP 4, PHP 5, PHP 7)
The dir() function is used to get an instance of the
Directory class which we can be used for reading a directory.
Note: The order in which the directory entries are returned
(when calling the read() method) depends on the operating
system.
Procedurálne
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $directory | string | The path to the directory. | |
| $context | resource | The context contains parameters and options, that affect the behavior of the stream. |
Mávratovej hodnoty
Vracia: Directory
Returns an instance of the Directory class or null
with wrong parameters. Returns false if an error occurs.
Príklady
<?php
$directory = dir('../'); // getting an instance of the Directory class
echo 'Path: ' . $directory->path . '<br>';
echo 'Contents:<br>';
// reading individual entries (file names, folder names)
while ($entry = $directory->read()) {
echo $entry.'<br>';
}
$directory->close(); // closing the directory
