채택완료

첨부파일로 이미지 첨부하면....

어떤 경로로 본문에 이미지로 출력되나요?

관련 소스 위치 좀 알려주세요.

|

답변 2개 / 댓글 2개

채택된 답변
+20 포인트
2015-07-12 (일) 09:00:19

/skin/board/basic/view.skin.php 파일 150~165라인의 php 코드로 출력됩니다.

Copy
​<?php        // 파일 출력        $v_img_count = count($view['file']);        if($v_img_count) {            echo "<div id=\"bo_v_img\" style='text-align:center'>\n";             for ($i=0; $i<=count($view['file']); $i++) {                if ($view['file'][$i]['view']) {                    //echo $view['file'][$i]['view'];                    echo get_view_thumbnail($view['file'][$i]['view']);                }            }             echo "</div>\n";        }?>
​ 

$view['file'][$i]['view'] 변수는 /lib/common.lib.php 파일​ 277~307라인 

get_file​() 함수 중 298라인에 있습니다.

Copy
​// 게시글에 첨부된 파일을 얻는다. (배열로 반환)function get_file($bo_table, $wr_id){    global $g5, $qstr;     $file['count'] = 0;    $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no ";    $result = sql_query($sql);    while ($row = sql_fetch_array($result))    {        $no = $row['bf_no'];        $file[$no]['href'] = G5_BBS_URL."/download.php?bo_table=$bo_table&amp;wr_id=$wr_id&amp;no=$no" . $qstr;        $file[$no]['download'] = $row['bf_download'];        // 4.00.11 - 파일 path 추가        $file[$no]['path'] = G5_DATA_URL.'/file/'.$bo_table;        $file[$no]['size'] = get_filesize($row['bf_filesize']);        $file[$no]['datetime'] = $row['bf_datetime'];        $file[$no]['source'] = addslashes($row['bf_source']);        $file[$no]['bf_content'] = $row['bf_content'];        $file[$no]['content'] = get_text($row['bf_content']);        //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']);        $file[$no]['view'] = view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content']);        $file[$no]['file'] = $row['bf_file'];        $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640;        $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480;        $file[$no]['image_type'] = $row['bf_type'];        $file['count']++;    }     return $file;}
​ 

1286~1318라인의 view_file_link() 함수를 거쳐 이미지로 추출합니다.​

 

Copy
// 파일을 보이게 하는 링크 (이미지, 플래쉬, 동영상)function view_file_link($file, $width, $height, $content=''){    global $config, $board;    global $g5;    static $ids;     if (!$file) return;     $ids++;     // 파일의 폭이 게시판설정의 이미지폭 보다 크다면 게시판설정 폭으로 맞추고 비율에 따라 높이를 계산    if ($width > $board['bo_image_width'] && $board['bo_image_width'])    {        $rate = $board['bo_image_width'] / $width;        $width = $board['bo_image_width'];        $height = (int)($height * $rate);    }     // 폭이 있는 경우 폭과 높이의 속성을 주고, 없으면 자동 계산되도록 코드를 만들지 않는다.    if ($width)        $attr = ' width="'.$width.'" height="'.$height.'" ';    else        $attr = '';     if (preg_match("/\.({$config['cf_image_extension']})$/i", $file)) {        $img = '<a href="'.G5_BBS_URL.'/view_image.php?bo_table='.$board['bo_table'].'&amp;fn='.urlencode($file).'" target="_blank" class="view_image">';        $img .= '<img src="'.G5_DATA_URL.'/file/'.$board['bo_table'].'/'.urlencode($file).'" alt="'.$content.'">';        $img .= '</a>';         return $img;    }}
 

마지막으로 /lib/thumbnail.lib.php 파일 75~185라인의 

썸네일 생성 함수 get_view_thumbnail() 를 거쳐서 출력됩니다.

Copy
// 게시글보기 썸네일 생성function get_view_thumbnail($contents, $thumb_width=0){    global $board, $config;     if (!$thumb_width)        $thumb_width = $board['bo_image_width'];     // $contents 중 img 태그 추출    $matches = get_editor_image($contents, true);     if(empty($matches))        return $contents;     for($i=0; $i<count($matches[1]); $i++) {         $img = $matches[1][$i];        preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);        $src = $m[1];        preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);        $style = $m[1];        preg_match("/width:\s*(\d+)px/", $style, $m);        $width = $m[1];        preg_match("/height:\s*(\d+)px/", $style, $m);        $height = $m[1];        preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);        $alt = get_text($m[1]);         // 이미지 path 구함        $p = parse_url($src);        if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)            $data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);        else            $data_path = $p['path'];         $srcfile = G5_PATH.$data_path;         if(is_file($srcfile)) {            $size = @getimagesize($srcfile);            if(empty($size))                continue;             // jpg 이면 exif 체크            if($size[2] == 2 && function_exists('exif_read_data')) {                $degree = 0;                $exif = @exif_read_data($srcfile);                if(!empty($exif['Orientation'])) {                    switch($exif['Orientation']) {                        case 8:                            $degree = 90;                            break;                        case 3:                            $degree = 180;                            break;                        case 6:                            $degree = -90;                            break;                    }                     // 세로사진의 경우 가로, 세로 값 바꿈                    if($degree == 90 || $degree == -90) {                        $tmp = $size;                        $size[0] = $tmp[1];                        $size[1] = $tmp[0];                    }                }            }             // 원본 width가 thumb_width보다 작다면            if($size[0] <= $thumb_width)                continue;             // Animated GIF 체크            $is_animated = false;            if($size[2] == 1) {                $is_animated = is_animated_gif($srcfile);            }             // 썸네일 높이            $thumb_height = round(($thumb_width * $size[1]) / $size[0]);            $filename = basename($srcfile);            $filepath = dirname($srcfile);             // 썸네일 생성            if(!$is_animated)                $thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);            else                $thumb_file = $filename;             if(!$thumb_file)                continue;             if ($width) {                $thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"/>';            } else {                $thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'"/>';            }             // $img_tag에 editor 경로가 있으면 원본보기 링크 추가            $img_tag = $matches[0][$i];            if(strpos($img_tag, G5_DATA_DIR.'/'.G5_EDITOR_DIR) && preg_match("/\.({$config['cf_image_extension']})$/i", $filename)) {                $imgurl = str_replace(G5_URL, "", $src);                $thumb_tag = '<a href="'.G5_BBS_URL.'/view_image.php?fn='.urlencode($imgurl).'" target="_blank" class="view_image">'.$thumb_tag.'</a>';            }             $contents = str_replace($img_tag, $thumb_tag, $contents);        }    }     return $contents;}

답변에 대한 댓글 1개

이렇게 자세히 설명해주시다니, 정말 고맙습니다. ^^
2015-07-13 (월) 08:14:10

홈짱님, 답변을 채택해 주셔서 감사드립니다. (_ _)

답변에 대한 댓글 1개

제가 더 고맙죠. ^__________________________^

답변을 작성하려면 로그인이 필요합니다.