case.1.특정 디렉토리 파일 목록 출력

<?php

$TargetDir    =    "[ DIRECTORY PATH ]";

if ($handle = opendir( $TargetDir ))
{
    while (false !== ($entry = readdir($handle)))
    {
        if ($entry != "." && $entry != "..")
        {
            echo $entry."\n";
            
        }//    end if
        
    }//    end while
}//    end if


?>

 

case.2.특정 디렉토리 파일 목록 출력

<?php

//---------------------------------------------------------------------------
//	@ 특정디렉토리 파일 목록 출력

$directory = '/path/to/directory';
$files = scandir($directory);
foreach ($files as $file) {
    if (is_file("$directory/$file")) {
        echo $file . "<br>";
    }
}

//---------------------------------------------------------------------------
//	@ 특정디렉토리에서 TXT 파일만 출력

$directory = '/path/to/directory';
$files = scandir($directory);
foreach ($files as $file) {
    if (is_file("$directory/$file")) {
        $pathinfo = pathinfo($file);
        if ($pathinfo['extension'] == 'txt') {
            echo $file . "<br>";
        }
    }
}

//---------------------------------------------------------------------------
//	@ 특정디렉토리에서 TXT 파일만 출력

$directory = '/path/to/directory';
$files = scandir($directory);
foreach ($files as $file) {
    if (is_file("$directory/$file"))
    {
        echo $file . ' ' . filesize("$directory/$file") . ' ' . date('Y-m-d H:i:s', filemtime("$directory/$file")) . "<br>";
    }
}


?>