Hàm closedir () trong PHP
Thí dụ
Mở một thư mục, đọc nội dung của nó, 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 closeir () đóng một xử lý thư mục.
Cú pháp
closedir(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: | - |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu thư mục PHP