نمایش محتویات یک شاخه

mgh67

Member
سلام
من از کد زیر برای نمایش محتویات یک شاخه استفاده می کنم ولی یه مشکل داره اونم اینه که دوبار تمام محتویات شاخه رو چاپ میکنه؟به نظر شما چیکار کنم؟
PHP:
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }
    /* This is the WRONG way to loop over the directory. */
    while ($file = readdir($handle)) {
        echo "$file\n";
    }
    closedir($handle);
}

و همین طور از کد زیر هم استفاده کردم اما باز هم همون طور بود

PHP:
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
 

جدیدترین ارسال ها

بالا