php | 디렉토리 폴더 안의 파일 리스트 불러 오기
페이지 정보
작성자 100K5 작성일13-02-19 15:51 조회75,471회 댓글0건관련링크
본문
// 디렉토리 폴더 안의 파일 리스트를 배열로 담는다.
function myallfile($dir, $ext = '')
{
$file_arr = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
$type = filetype($dir . $file);
{
$file_arr = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
$type = filetype($dir . $file);
if($type == 'file')
{
if($ext != '')
{
$ext = strtolower($ext);
$temp = explode('.',$file);
if(strtolower($temp[count($temp)-1]) == $ext)
{
$file_arr[] = $dir.$file;
}
}
else
{
$file_arr[] = $dir.$file;
}
}
else if($type == 'dir' && ($file != '.' && $file != '..'))
{
{
if($ext != '')
{
$ext = strtolower($ext);
$temp = explode('.',$file);
if(strtolower($temp[count($temp)-1]) == $ext)
{
$file_arr[] = $dir.$file;
}
}
else
{
$file_arr[] = $dir.$file;
}
}
else if($type == 'dir' && ($file != '.' && $file != '..'))
{
$temp = myallfile($dir.$file.'/', $ext);
if(is_array($temp))
{
$file_arr = array_merge($file_arr, $temp);
}
}
}
closedir($dh);
}
return $file_arr;
}
return 0;
}
if(is_array($temp))
{
$file_arr = array_merge($file_arr, $temp);
}
}
}
closedir($dh);
}
return $file_arr;
}
return 0;
}
$ifle_dir = "/디렉토리/";
$file_arr = myallfile($ifle_dir);
$file_arr = myallfile($ifle_dir);
// echo "<br /> = ".print_r($file_arr);
$file_name = array();
$file_name = array();
sort($file_arr); // 파일 이름 순으로 정렬
foreach($file_arr as $key=>$val) {
echo "<br /> = ".$file_name[] = $ifle_dir.$val;
}
}
댓글목록
등록된 댓글이 없습니다.