PHP scandir() İşlevi
Örnek
Görüntüler dizini içindeki dosyaları ve dizinleri listeleyin:
<?php
$dir = "/images/";
// Sort in ascending order - this is default
$a = scandir($dir);
// Sort in descending order
$b = scandir($dir,1);
print_r($a);
print_r($b);
?>
Sonuç:
Array
(
[0] => .
[1] => ..
[2] => cat.gif
[3] => dog.gif
[4] => horse.gif
[5] => myimages
)
Array
(
[0] => myimages
[1] => horse.gif
[2] => dog.gif
[3] => cat.gif
[4] => ..
[5] => .
)
Tanım ve Kullanım
scandir() işlevi, belirtilen dizine ait bir dizi dosya ve dizin döndürür.
Sözdizimi
scandir(directory, order, context)
Parametre Değerleri
Parameter | Description |
---|---|
directory | Required. Specifies the directory to be scanned |
order | Optional. Specifies the sorting order. Default sort order is alphabetical in ascending order (0). Set to SCANDIR_SORT_DESCENDING or 1 to sort in alphabetical descending order, or SCANDIR_SORT_NONE to return the result unsorted |
context | Optional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream |
Teknik detaylar
Geri dönüş değeri: | Başarı durumunda bir dizi dosya ve dizin, başarısızlık durumunda FALSE. Dizin bir dizin değilse bir E_WARNING atar |
---|---|
PHP Sürümü: | 5.0+ |
PHP Değişiklik Günlüğü: | PHP 5.4: Sıra sabitleri eklendi |
❮ PHP Dizin Referansı