0
함수를 사용하여 모든 디렉토리와 하위 디렉토리에서 모든 파일 이름, 크기, 경로를 가져 오려고합니다. 재귀 함수를 사용하여 이미 동일한 작업을 수행했습니다. 여기 내 코드가있다.디렉토리와 하위 디렉토리에서 모든 파일, 크기, 경로 가져 오기 php
function scan_dir($path, $exclude){
$ite = new RecursiveDirectoryIterator($path);
$bytestotal=0;
$nbfiles=0;
$file_data = array();
$i= 0;
foreach (new RecursiveIteratorIterator($ite,RecursiveIteratorIterator::CHILD_FIRST) as $filename => $cur) {
if ($cur->isDir())
{
continue ;
}
$files = str_replace('\\','/', $filename);
$filesize = $cur->getSize();
$exclude = array_filter($exclude);
$data = array('name'=>$files, 'path'=>$cur->getPath(),'size'=>$cur->getSize());
$file_data[] = $data;
$i++;
$nbfiles++;
$bytestotal += $filesize;
}
$bytestotal = $bytestotal;
return array('total_files'=> $nbfiles, 'total_size' => $bytestotal, 'files'=> $file_data);
}
문제는 재귀 기능으로 인해 Linux 서버에서 코드를 실행할 때 느리게 실행됩니다. 제발 내가 같은 출력을 얻을 수 있지만 다른 기능을 사용할 수있는 동일한 대체 할 수 있습니다.
나는 그 다음 다른 {}가 {재귀 함수가} 이 어떤 도움이 정말 감사합니다 리눅스입니다 경우, 서버를 확인 즉 다른 경우 파트를 추가하고 싶습니다.
혼자 리눅스에 대한 체크는 그것을 잘라하지 않을 것입니다. 속도는 일반적으로 트리 및 기본 파일 시스템의 깊이/크기로 인해 발생합니다. 어쩌면 깊이를 줄여야 할 필요가 있습니다 (재귀 반복자를 사용하면 깊이를 제어 할 수 있습니다 http://www.php.net/recursiveiteratoriterator.setmaxdepth) – hakre