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

첨부파일로 이미지 첨부하면.... 채택완료

홈짱 10년 전 조회 4,099

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

 

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

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

답변 2개

채택된 답변
+20 포인트

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

 

</strong><span style="font-size: 11pt; line-height: 1.5;">​</span><span style="font-size: 11pt; line-height: 1.5;"><?php</span></p><p>        // 파일 출력</p><p>        $v_img_count = count($view['file']);</p><p>        if($v_img_count) {</p><p>            echo "<div id=\"bo_v_img\" style='text-align:center'>\n";</p><p> </p><p>            for ($i=0; $i<=count($view['file']); $i++) {</p><p>                if ($view['file'][$i]['view']) {</p><p>                    //echo $view['file'][$i]['view'];</p><p>                    echo get_view_thumbnail($view['file'][$i]['view']);</p><p>                }</p><p>            }</p><p> </p><p>            echo "</div>\n";</p><p>        }</p><p>?><strong style="color: rgb(127, 127, 127); font-family: 돋움, Dotum, sans-serif; font-size: 12px; line-height: normal;">
 

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

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

 

</strong><span style="font-size: 11pt; line-height: 1.5;">​</span><span style="font-size: 11pt; line-height: 1.5;">// 게시글에 첨부된 파일을 얻는다. (배열로 반환)</span></p><p>function get_file($bo_table, $wr_id)</p><p>{</p><p>    global $g5, $qstr;</p><p> </p><p>    $file['count'] = 0;</p><p>    $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no ";</p><p>    $result = sql_query($sql);</p><p>    while ($row = sql_fetch_array($result))</p><p>    {</p><p>        $no = $row['bf_no'];</p><p>        $file[$no]['href'] = G5_BBS_URL."/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr;</p><p>        $file[$no]['download'] = $row['bf_download'];</p><p>        // 4.00.11 - 파일 path 추가</p><p>        $file[$no]['path'] = G5_DATA_URL.'/file/'.$bo_table;</p><p>        $file[$no]['size'] = get_filesize($row['bf_filesize']);</p><p>        $file[$no]['datetime'] = $row['bf_datetime'];</p><p>        $file[$no]['source'] = addslashes($row['bf_source']);</p><p>        $file[$no]['bf_content'] = $row['bf_content'];</p><p>        $file[$no]['content'] = get_text($row['bf_content']);</p><p>        //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']);</p><p>        $file[$no]['view'] = view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content']);</p><p>        $file[$no]['file'] = $row['bf_file'];</p><p>        $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640;</p><p>        $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480;</p><p>        $file[$no]['image_type'] = $row['bf_type'];</p><p>        $file['count']++;</p><p>    }</p><p> </p><p>    return $file;</p><p>}<strong style="color: rgb(127, 127, 127); font-family: 돋움, Dotum, sans-serif; font-size: 12px; line-height: normal;">
 

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

 

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

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

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

 

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

홈짱
10년 전
이렇게 자세히 설명해주시다니, 정말 고맙습니다. ^^

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

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

홈짱
10년 전
제가 더 고맙죠. ^__________________________^

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

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

로그인