Hàm readdir () trong PHP
Thí dụ
Liệt kê tất cả các mục trong thư mục hình ảnh, sau đó đóng:
<?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);
}
}
?>
Kết quả:
filename: cat.gif
filename: dog.gif
filename: horse.gif
Định nghĩa và Cách sử dụng
Hàm readdir () trả về tên của mục nhập tiếp theo trong một thư mục.
Cú pháp
readdir(dir)
Giá trị tham số
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 |
Chi tiết kỹ thuật
Giá trị trả lại: | Tên mục nhập (tên tệp) thành công, FALSE nếu thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu thư mục PHP