간단하게 만들어본 디렉토리 이미지 뷰어

<?php

$Ypattern_extension
= 'gif|jpg|jpeg|png';
//확인할 이미지 지정
$Ydir_path_img = './imgviewer/';
//확인할 이미지 디렉토리 경로, 절대경로 or 상대경로, 맨마지막에 / 반듯이 붙일것
$Yfile_name_listing = '';
//해당파일이 이미지 경로에 존재하면 그것을 참조로 리스팅, ex)list.txt
$Ycheck_file = 0;
//파일의 존재유무를 체크 할것인가?, 체크할경우 1, 체크하지 않을 경우 0
$Yimg_width = 200;
//이미지 넓이
$Ynum_line = 4;
//한라인에 보여줄 이미지 개수
$Ynum_page = 12;
//한페이지에 보여줄 개수 설정
$Ynum_pageblock = 10;
//한페이지에 보여줄 페이지블럭수 설정


if (!is_dir($Ydir_path_img
)) {

echo
"지정한 디렉토리가 존재하지 않습니다."
;
exit;
}

if (empty(
$page)) $page = 1
;
$start_line = ($page - 1) *10
;
$total = 0
;
$view_array
= Array();

//참조 파일이 존재하면 참조파일을 참조함
if (!empty($Yfile_name_listing) && is_file($Ydir_path_img . $Yfile_name_listing
)) {

$list = file($Ydir_path_img . $Yfile_name_listing
);

if (
is_array($list
)){

   foreach(
$list as $value
){

     
$value = trim($value
);

     
//해당 라인이 비었으면 넘어감
     
if (empty($value
)) continue;

     
//해당 라인이 #으로 시작하면 주석으로 간주하고 넘어감
     
if (preg_match("`^#`", $value
)) continue;

     
$temp = explode('|', $value
);
     if (
count($temp) > 1
) {

       
$temp[0] = trim($temp[0]);
//파일명
       
if ($Ycheck_file == 1
) {

         if (
is_file($Ydir_path_img . $temp[0
])) {

           if (
$total >= $start_line && $total < $start_line + $Ynum_page
) {

             
$view_array[] = $temp
;
           }

           
$total
++;
         }
       }
       else {

         if (
$total >= $start_line && $total < $start_line + $Ynum_page
) {

           
$view_array[] = $temp
;
         }

         
$total
++;
       }
     }
   }
}
}
else{
//참조된 파일이 없으므로 지정된 디렉토리에서 직접 찾는 형태


$all_array
= Array();
$d = dir($Ydir_path_img
);
while (
false !== ($entry = $d->read
())) {
   
   if (
is_file($Ydir_path_img . $entry) && preg_match("`\." . $Ypattern_extension . "$`i", $entry
)) {

     
$mtime = filemtime($Ydir_path_img . $entry
);
     
$all_array[$mtime] = $entry
;
   }
   else{

     continue;
   }
}
$d->close
();

if (
is_array($all_array
)){

   
krsort($all_array
);
   
reset ($all_array
);
   
$i = 0
;
   foreach(
$all_array as $temp
){
     
     if (
$total >= $start_line && $total < $start_line + $Ynum_page
) {

       
$view_array[$i][0] = $temp
;
       
$view_array[$i][1] = $temp
;
       
$i
++;
     }

     
$total
++;
   }
}

}

?>
<table width=900 align="center">
   
<?php

if (count($view_array) == 0
) {

echo
"<tr><td height=50>등록된 이미지 없습니다.<td></tr>\n"
;
}
else{

$cnt = 0
;
for (
$i = 0; $i < ceil($Ynum_page / $Ynum_line); $i
++){

   for(
$j = 0; $j < $Ynum_line; $j
++){

     if (empty(
$view_array[$cnt][0
])){

       
$temp_image = 'no image'
;
       
$temp_title = ''
;
     }
     else {

       
$temp_title = $view_array[$cnt][1
];
       if (!
is_file($Ydir_path_img . $view_array[$cnt][0
])){

         
$temp_image = 'not find image'
;
       }
       else{

         
$temp_image = "<img src='" . $Ydir_path_img . $view_array[$cnt][0] . "' width=" . $Yimg_width . ">"
;
       }
     }

     if (
$j == 0) echo "<tr>"
;
     echo
"<td width=" . (100 / $Ynum_line) . "% valign=top><table width=" . $Yimg_width . " align=center><tr><td align=center valign=middle>" . $temp_image . "</td></tr><tr><td>" . $temp_title . "</td></tr></table><td>\n"
;
     if (
$j == $Ynum_line - 1) echo "</tr>"
;

     
$cnt
++;
   }
}
}

?>
</table>

<br>
<table width=900 align="center">
<tr>
   <td>
<?php

//그냥 그누보드꺼 사용
// 현재페이지, 총페이지수, 한페이지에 보여줄 행, URL
function get_paging($write_pages, $cur_page, $total_page, $url, $add=""
)
{
   
$str = ""
;
   if (
$cur_page > 1
) {
       
$str .= "<a href='" . $url . "1{$add}'>처음</a>"
;
       
//$str .= "[<a href='" . $url . ($cur_page-1) . "'>이전</a>]";
   
}

   
$start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1
;
   
$end_page = $start_page + $write_pages - 1
;

   if (
$end_page >= $total_page) $end_page = $total_page
;

   if (
$start_page > 1) $str .= " &nbsp;<a href='" . $url . ($start_page-1) . "{$add}'>이전</a>"
;

   if (
$total_page > 1
) {
       for (
$k=$start_page;$k<=$end_page;$k
++) {
           if (
$cur_page != $k
)
               
$str .= " &nbsp;<a href='$url$k{$add}'><span>$k</span></a>"
;
           else
               
$str .= " &nbsp;<b>$k</b> "
;
       }
   }

   if (
$total_page > $end_page) $str .= " &nbsp;<a href='" . $url . ($end_page+1) . "{$add}'>다음</a>"
;

   if (
$cur_page < $total_page
) {
       
//$str .= "[<a href='$url" . ($cur_page+1) . "'>다음</a>]";
       
$str .= " &nbsp;<a href='$url$total_page{$add}'>맨끝</a>"
;
   }
   
$str .= ""
;

   return
$str
;
}

if (empty(
$total)) $total = 1
;
$total_page = ceil($total / $Ynum_pageblock
);
echo
get_paging($Ynum_pageblock, $page, $total_page, 'Yimg_viewer.php?page='
);

?>
   </td>
</tr>
</table>



샘플url http://82da.com/Ybbs/sample/Yimg_viewer.php
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 바람부는데로

, , ,
Response
No Trackback , No Comment
RSS :
http://apmusers.com/tt/dbckdghk/rss/response/15

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

« Previous : 1 : ... 78 : 79 : 80 : 81 : 82 : 83 : 84 : 85 : 86 : ... 87 : Next »

블로그 이미지

유창화의 블로그(사진은 10년전 모습)

- 바람부는데로

Archives

Calendar

«   2010/09   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

이올린 추천글

Site Stats

Total hits:
176466
Today:
20
Yesterday:
119