2013-10-19 3 views
1

$ dir = array ('images/posters', 'images/designs', 'images/illustrations')와 같이 하위 폴더 내에있는 모든 이미지를 어떻게 표시합니까? ??php는 폴더와 하위 폴더 내의 이미지를 표시합니다.

코드 :

<?php 
    $dir = 'img/werk/'; 
    $file_display = array('jpg', 'jpeg', 'png', 'gif'); 

    if (file_exists($dir) == false) { 
     echo 'Directory \'', $dir, '\' not found!'; 
    } else { 
    $dir_content = scandir($dir); 

    foreach ($dir_content as $file) { 
     $file_type = strtolower(end(explode('.', $file))); 

     if ($file !== '.' && $file !== '..' 
          && in_array($file_type, $file_display) == true) { 
      echo '<div class="thing large"><div class="item_description">Item description</div><img src="', $dir, '/', $file, '" /></div>'; 
     } 
     } 
    } 
?> 

답변

1

이것은 내가 폴더를 촬영하고 그 안에있는 모든 이미지를 표시하고 웹 페이지에 표시 한 방법이다. (모두 PHP에서)

코드는 다른 형식의 이미지를 가져 와서 파일 이름 아래에 웹 페이지에 넣습니다.

$files = glob($root."Images/*.*"); 
echo '<table width="750px" id="autoimage" align="center">'; 
for ($i=0; $i<count($files); $i++) 
{ 
echo '<tr height="20px"><td colspan="2"></td></tr><tr><td width="325px" align="center">'; 
if(isset($files[$i])){ 
    $num = $files[$i]; 
    echo '<img width="300px" src="'.$num.'" alt="Image" />'."<br /><br />"; 
    $num1 = str_replace($root.'Images/', '', $num); 
    if (strpos($num1,'.png') == true) 
    { 
     $text = str_replace('.png', '', $num1); 
    } 
    if (strpos($num1,'.jpeg') == true) 
    { 
     $text = str_replace('.jpeg', '', $num1); 
    } 
    if (strpos($num1,'.jpg') == true) 
    { 
     $text = str_replace('.jpg', '', $num1); 
    } 
    if (strpos($num1,'.tiff') == true) 
    { 
     $text = str_replace('.tiff', '', $num1); 
    } 
    if (strpos($num1,'.gif') == true) 
    { 
     $text = str_replace('.gif', '', $num1); 
    } 
    print "<p>".$text."</p><br />"; 
} 
echo '</td></tr><tr height="20px"><td colspan="2"></td></tr><tr>'; 
} 
echo '</table>'; 

하위 폴더를 가져 오려면 비슷한 일을하고 코드가 찾고있는 위치를 변경하십시오.

+0

고마워, 이건 좋은 코드지만, 이미 해결 된 것 같아. :)이 포럼을 사랑해. – Auguste

관련 문제