테스트 사이트 - 개발 중인 베타 버전입니다

디렉토리 이미지 뷰어

· 19년 전 · 3126 · 18
머리가 좀 아파서
쉴겸 해서 만들어봤습니다.

썸네일 기능은 넣지 않앗습니다.
충분히 응용가능하리라고 봅니다.

사용방식은 크게 두가지 입니다.
list.txt를 참조하는 방식과
그냥 디렉토리를 읽어서 하는 방식입니다.

이하 소스입니다.



$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><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 18개

멋진 자료입니다.

오전에 등록된 내용을,

머리 식힌다는 핑계로

일 삼아(^^;) 만들어 주셨군요.

고생하셨습니다.

ㅎㅎ 고맙습니다
일반적으로 y(Y)로 시작되는 리눅스관련 명령어가
프로그래머의 습관에 의해 존재하지 않았던 부분이 못마땅했었는데,
'유창화'님의 자료에서는 줄곧 보게 되는군요^^;
'성'의 이니셜이라 짐작됩니다.
ㅎㅎ 맞아요
음 인기없네요 ㅎㅎ
list.txt를 참조하는 방식의 장점은
정렬을 사용자 임의로 조정할수 있고
보여주기 싫은 이미지는 안보여줄수 있고
파일명 외에 | 구분자로 제목, 내용 같은 것을 넣어
갤러리 게시판 형태로 만들수 있다는 점입니다.

썸네일이나 보기 페이지, 슬라이드 페이지 이런거 추가해서 넣으면
괜찬은 디렉토리 갤러리 를 만들수 있지 않을 까 생각됩니다.
접근이 어려운 부분이라 생각될 수 있으므로,

클릭이 다소 지연되었을 가능성도 있습니다.

결코 자주 접하기는 쉽지 않은 자료임에도 불구하고...

못 지우게 코멘트로 한번 더 살짝 발목 잡아주는 센스~*
ㅎㅎ
유창화님 올리시는 자료에 알찬 내용이 많은것 같습니다.

수고하셨습니다. 감사합니다 ^^
고맙습니다.
근데 제가 올리는 팁들은 모두 대부분

file (image), dir, socket 이 대부분입니다.
겁나 어려운 부분만 하십니다.

접근하기가 무쟈게 껄끄러운 부분들~*^^*

게시글 목록

번호 제목
10331
28724
10329
10328
10326
10324
10323
28723
10322
10321
10320
28722
10318
28719
10317
10314
10312
28716
10308
10307
10306
10305
28715
10304
10303
28714
10302
28713
10301
10300
10299
10296
10294
10293
10292
10291
10289
10285
28711
10281
10279
28710
10278
10277
10276
28709
10273
10270
10269
10267
28708
10266
10264
10263
10261
28707
10260
10256
10255
28706
10253
28704
10250
28703
28702
10249
10247
10245
10243
10240
10239
10238
10237
10235
10225
28700
10213
10210
10207
10205
10204
28693
10198
10195
10191
24785
28674
24784
10189
10187
10182
28669
10181
10175
24779
24772
10173
10168
10163
10160