PHP - Code to traverse a directory and get all the files(images)

前端 未结 10 1826
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 13:00

i want to write a page that will traverse a specified directory.... and get all the files in that directory...

in my case the directory will only contain images and dis

10条回答
  •  面向向阳花
    2021-01-27 13:33

    $dir = "/etc/php5/";
    

    // Open a known directory, and proceed to read its contents

    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
            }
            closedir($dh);
        }
    }
    

    For further reference :http://php.net/manual/en/function.opendir.php

提交回复
热议问题