溫馨提示×

php opendir和closedir配合使用

PHP
小樊
90
2024-07-14 17:27:29
欄目: 編程語言

<?php
$dir = '/path/to/directory';

// Open the directory
$handle = opendir($dir);

// Check if the directory was opened successfully
if ($handle) {
    // Read all files in the directory
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }
    
    // Close the directory
    closedir($handle);
} else {
    echo "Failed to open directory\n";
}
?>

在這個示例中,我們首先使用opendir()函數打開指定目錄,然后使用readdir()函數讀取目錄中的文件,并在控制臺輸出文件名。最后,我們使用closedir()函數關閉目錄句柄。如果目錄無法打開,則輸出“Failed to open directory”。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女