PHP gets file directory list

高洛峰
Release: 2016-10-21 11:07:54
Original
1910 people have browsed it

Because we are traversing a certain folder, we must pass the address parameter $path of a file directory

function getDirList($path = '.') {    
    $allDirList = scandir($path);    
    foreach($allDirList as $key=>$val){        
        if (is_dir($path.$val) && $val!="." &&$val!="..") {            
            $filterDirList[] = $val;        
        }    
    }    
    return  $filterDirList;
}
Copy after login


The above method is to traverse the directories and files in each directory again through a foreach loop.

scandir method:

If successful, it will return an array containing the file name, if it fails, it will return FALSE. If directory is not a directory, a Boolean value of FALSE is returned and an E_WARNING level error is generated.


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template