현재 I했습니다 다음과 같은 트리 구조와 유사 : 나는 PHP에 매우 새로 온 사람으로에서 배열의 모든 이미지를 얻을 수 디렉토리 및 하위 디렉토리
+images
+sub-directory
-image1.jpg
-image2.jpg
+sub-directory-2
-image3.jpg
-image4.jpg
-some-image.jpg
-another.jpg
<script>
<?php
//path to directory to scan. i have included a wildcard for a subdirectory
$directory = "images/*/";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");
$imgs = '';
// create array
foreach($images as $image){ $imgs[] = "$image"; }
echo "var allImages = ".$imgs.";\n";
?>
console.log(allImages);
</script>
, 내가 ' m 맹목적으로 콘솔에 Array()
로 기록됩니다.
또한 $directory = "images/*/";
을 설정했는데 하위 폴더에만있는 모든 이미지를 가져 오지만 상위 디렉토리에있는 이미지는 images/some-image.jpg
일 가능성이 높습니다.이 이미지도 얻으려고합니다.
['some-image.jpg','another.jpg','image1.jpg','image2.jpg','image3.jpg','image4.jpg']
하위 디렉토리와 얼마나 멀리 떨어져 있습니까? 필자가 깊이가 없다면 php glob 매뉴얼 페이지에 여러 재귀 glob 함수가 있기 때문에 물어볼 것이다. 그것이 상당히 깊다면, 아마도 find를 사용하여 exec를 사용하는 것이 더 빠른 결과를 줄 것입니다. –
@JonathanKuhn 현재 하위 디렉토리가별로 없으며 괜찮습니다. –