방법1
<?php
$mydir = 'directory';
$myfiles = array_diff(scandir($mydir), array('.', '..'));
print_r($myfiles);
?>
#결과
Array (
[2] => hello.txt
[3] => world.txt
[4] => test.php
[5] => test2.php
)
directory 폴더안에 있는 파일들을 가져오는데, "."와 ".."는 제외합니다.
linux환경에서 "."가 의미하는 건 현재 디렉토리이고, ".."는 전 디렉토리를 의미합니다.
방법2
<?php
$fileList = glob('directory/*');
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>';
}
}
?>
#결과
directory/hello.txt
directory/world.txt
directory/test.php
directory/test2.php
directory안에 "*"모든 파일 리스트를 불러와서 화면에 보여주는 것 입니다.
"*.php"로 하면, 확장자가 php인 모든 파일만 불러올 수 있습니다.
'IT 공부 > PHP' 카테고리의 다른 글
[ PHP ] CSV파일 내용 불러오기 (Spreadsheet 와 fgetcsv) (0) | 2022.03.02 |
---|---|
[ PHP ] 연관배열에서 특정키(index)값이 존재하는지 확인하고 싶을 경우 (0) | 2022.02.20 |
[ PHP ] Pagination (페이징) 구현 (0) | 2022.02.16 |
[ PHP ] Project 디렉토리에 있는 파일을 Web에서 Download (0) | 2022.02.15 |
[ PHP ] CSV파일 불러와서 웹에 Table 형태로 뿌려주기 (0) | 2022.02.15 |