Funkcja rewinddir() w PHP
Przykład
Otwórz katalog, wyświetl jego pliki, zresetuj uchwyt katalogu, ponownie wyświetl jego pliki, a następnie zamknij:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
rewinddir();
// List once again files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
Wynik:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
Definicja i użycie
Funkcja rewinddir() resetuje uchwyt katalogu utworzony przez opendir() .
Składnia
rewinddir(dir)
Wartości parametrów
Parameter | Description |
---|---|
dir | Optional. Specifies the directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed |
Szczegóły techniczne
Wartość zwrotu: | NULL w przypadku sukcesu, FALSE w przypadku niepowodzenia |
---|---|
Wersja PHP: | 4.0+ |
❮ Odniesienie do katalogu PHP