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

파일첨부시 1번파일만 사이즈를 줄일수 있을까요? 채택완료

룽즈 4년 전 조회 3,527

thisgun님의 게시판에 파일 업로드시 이미지 파일 용량 줄이기 플러그인을 설치했습니다

https://sir.kr/g5_plugin/6165" rel="nofollow noreferrer noopener" target="_blank">https://sir.kr/g5_plugin/6165

 

1번 파일만 따로 뽑아서 전송할 곳이 있어서 이 플러그인을 1번파일만 적용하고싶은데

문제는 이걸 설정해놓으면 2번,3번.... 파일들도 일괄 적용되어 버립니다..ㅠ ㅠ

 

혹시 파일첨부시 1번 첨부파일만 이 플러그인이 적용되게 할수 있을까요?

 

코드는 이렇습니다

</p>

<p><?php

if (!defined('_GNUBOARD_')) exit; // Unable to access direct pages</p>

<p>//return;</p>

<p>/*

// 게시판의 경우 게시판 설정에서 이미지 폭 크기 값으로 resize 됩니다.

// 에디터 이미지 경우 아래 상수에 width 값을 지정해 주세요.

*/

define('CUSTOM_EDITOR_RESIZE_WIDTH', 1200);</p>

<p>add_replace('write_update_upload_file', 'custom_upload_file_resize', 10, 4);

add_replace('get_editor_upload_url', 'custom_editor_upload_url', 10, 3);</p>

<p>// bbs/view_image.php 에서 이미지를 호출시 위의 상수값 CUSTOM_EDITOR_RESIZE_WIDTH 보다 이미지 width 값이 크다면 CUSTOM_EDITOR_RESIZE_WIDTH 으로 파일을 리사이즈 합니다.

add_replace('get_view_imagesize', 'custom_get_view_imagesize', 10, 3);</p>

<p>function custom_get_view_imagesize($size, $filepath, $editor_file){</p>

<p>    if( isset($size[0]) && (int) $size[0] > CUSTOM_EDITOR_RESIZE_WIDTH ){

        $filepath = custom_imagefile_resize($filepath, CUSTOM_EDITOR_RESIZE_WIDTH);

        $size = @getimagesize($filepath);

    }</p>

<p>    return $size;

}</p>

<p>function custom_imagefile_resize($dest_file, $thumb_width=0){</p>

<p>    include_once(G5_LIB_PATH.'/thumbnail.lib.php');</p>

<p>    $size = @getimagesize($dest_file);

    if(empty($size))

        return $dest_file;</p>

<p>    if(in_array($size[2], array(IMAGETYPE_JPEG, IMAGETYPE_PNG))) {</p>

<p>        if(function_exists('exif_read_data')) {

            // exif 정보를 기준으로 회전각도 구함

            $exif = @exif_read_data($dest_file);

            $degree = 0;

            if(!empty($exif['Orientation'])) {

                switch($exif['Orientation']) {

                    case 8:

                        $degree = 90;

                        break;

                    case 3:

                        $degree = 180;

                        break;

                    case 6:

                        $degree = -90;

                        break;

                }</p>

<p>                // 회전각도를 구한다.

                if($degree) {

                    // 세로사진의 경우 가로, 세로 값 바꿈

                    if($degree == 90 || $degree == -90) {

                        $tmp = $size;

                        $size[0] = $tmp[1];

                        $size[1] = $tmp[0];

                    }

                }

            }

        }</p>

<p>        // 원본 width가 thumb_width보다 작다면

        if($size[0] <= $thumb_width)

            return $dest_file;

        

        $thumb_height = ceil($thumb_width * $size[1] / $size[0]);</p>

<p>        $path_parts = pathinfo($dest_file);

        

        if( $path_parts['dirname'] ){

            $thumb = thumbnail($path_parts['basename'], $path_parts['dirname'], $path_parts['dirname'], $thumb_width, $thumb_height, true, true);</p>

<p>            if($thumb) {

                @unlink($dest_file);

                rename($path_parts['dirname'].'/'.$thumb, $dest_file);

            }

        }</p>

<p>    }</p>

<p>    return $dest_file;

}</p>

<p>function custom_editor_upload_url($fileurl, $filepath, $args=array()){

    global $config;</p>

<p>    if( $config['cf_editor'] === 'smarteditor2' && (defined('SMARTEDITOR_UPLOAD_RESIZE') && SMARTEDITOR_UPLOAD_RESIZE) ){

        return $fileurl;

    }</p>

<p>    if ( file_exists($filepath) && defined('CUSTOM_EDITOR_RESIZE_WIDTH') && CUSTOM_EDITOR_RESIZE_WIDTH ){

        

        $thumb_width = CUSTOM_EDITOR_RESIZE_WIDTH;

        $filepath = custom_imagefile_resize($filepath, $thumb_width); 

    }</p>

<p>    return $fileurl;

}</p>

<p>function custom_upload_file_resize($dest_file, $board, $wr_id, $w){

    for ($i=0; $i=count($_FILES['bf_file']['name']); $i++) {

    if( file_exists($dest_file) && $board['bo_image_width'] ){</p>

<p>        // 게시판 관리자에서 설정된 width 값

        $thumb_width = $board['bo_image_width'];</p>

<p>        $dest_file = custom_imagefile_resize($dest_file, $thumb_width);

    }</p>

<p>    return $dest_file;

}

}

?></p>

<p>

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

답변 2개

채택된 답변
+20 포인트
4년 전

위 소스 맨 마지막

$dest_file = custom_imagefile_resize($dest_file, $thumb_width); 다음 행에 추가

break; <--- 추가

 

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

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

쌩초보2
3년 전

롱즈님 이거 그냥 public_html > extend 폴더안에 넣으면 끝인가요 ?

파일 다운받고 압축풀어서 안에 파일 그냥 extend 안에 넣었는데 전혀 무반응입니다.

파일 용량 그대로 다 올라가네요

 

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

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

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

로그인