How to get the file name under a folder?

前端 未结 7 762
日久生厌
日久生厌 2020-12-18 01:43

Suppose I have a directory look like:

ABC
|_ a1.txt
|_ a2.txt
|_ a3.txt
|_ a4.txt
|_ a5.txt

How can I use PHP to get these file names to an

相关标签:
7条回答
  • 2020-12-18 02:35
    $dir = "your folder url"; //give only url, it shows all folder data
    
    if (is_dir($dir)){
        if ($dh = opendir($dir)){
            while (($file = readdir($dh)) !== false){
                if($file != '.' and $file != '..'){
                    echo $file .'<br>';
                }
            }
            closedir($dh);
        }
    }
    

    output:

    xyz
    abc
    2017
    motopress
    
    0 讨论(0)
提交回复
热议问题