PHP readdir ()ฟังก์ชั่น
ตัวอย่าง
แสดงรายการทั้งหมดในไดเร็กทอรีภาพ จากนั้นปิด:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
ผลลัพธ์:
filename: cat.gif
filename: dog.gif
filename: horse.gif
ความหมายและการใช้งาน
ฟังก์ชัน readdir() จะคืนค่าชื่อของรายการถัดไปในไดเร็กทอรี
ไวยากรณ์
readdir(dir)
ค่าพารามิเตอร์
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 |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ชื่อรายการ (ชื่อไฟล์) เมื่อสำเร็จ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 4.0+ |
❮ การอ้างอิงไดเรกทอรี PHP