Answers for "php get list of folder in current directory"

PHP
1

php directory listing

if ($handle = opendir('.')) {

    while (false !== ($entry = readdir($handle))) {

        if ($entry != "." && $entry != "..") {

            echo "$entry\n";
        }
    }

    closedir($handle);
}
Posted by: Guest on June-08-2020
0

php get list of filenames in diretory

<?php
// $dir is dir you want to return names of files and folders (first level - not recursive)
$dir    = '/tmp'; // './' for the root for the file calling scandir
$files1 = scandir($dir); // assending list
$files2 = scandir($dir, 1); //desending list 

print_r($files1);
print_r($files2); //frist files then folders alphabetically respective of types

//output $files1 order of folders then files alphabetically respective of types
//Array
// (
//    [0] => .
//    [1] => ..
//    [2] => folder1
//    [3] => folder2
//    [4] => folder3
//    [2] => file1
//    [2] => file2
//    [2] => file3
// )

?>
Posted by: Guest on November-12-2021

Code answers related to "php get list of folder in current directory"

Browse Popular Code Answers by Language