게시글 첨부파일 용량 체크

게시글 첨부파일 용량 체크

QA

게시글 첨부파일 용량 체크

본문

게시글 작성시 첨부파일 용량이 정해진 사이즈가 클 경우에 첨부파일이 빠진 상태로 글이 업로드됩니다.

https://sir.kr/g5_tip/8645 해당 글 참고하여 경고창을 띄우는 것을 작성하였는데 용량 체크가 안되네요 ㅠㅠ

뭐가 잘못된걸까여

 


<?php if (!defined('_GNUBOARD_')) exit;
 
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
 
// 제목 자동생성
$subject = date("Y-m-d H:i:s")." 문의";
 
// 문의분류 재생성 [공지]제거
$is_category = false;
if ($board['bo_use_category']) {
    $category_list = explode('|',$board['bo_category_list']);
    $is_category = true;
}
 
// 개인정보 처리방침 HTML 처리
$cfg = [];
for($idx=1; $idx<=10; $idx++) {
    $key = 'bo_'.$idx.'_subj';
    if($board[$key]) $cfg[$board[$key]] = $board['bo_'.$idx];
}
$privacy_html = '';
$privacy_html = file_get_contents($board_skin_path . '/privacy.html');
    foreach (explode('|',$cfg['개인정보처리방침']) as $idx=>$v) {
        $privacy_html = str_replace("{{{$idx}}}", $v, $privacy_html);
    }
 
// 캡챠 무조건 사용하도록 하기
$is_use_captcha = true;
$captcha_html = captcha_html();
$captcha_js   = chk_captcha_js();
 
/*
$name = '홍길동';
$email = '*** 개인정보보호를 위한 이메일주소 노출방지 ***';
$wr_1 = '개발팀';
$wr_2 = '팀장';
$wr_content = '안녕하세요';
//*/
?>
<form name="fwrite" id="fwrite" action="<?php echo $action_url ?>"
      onsubmit="return fwrite_submit(this);"
      method="post" enctype="multipart/form-data" autocomplete="off">
    <input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
    <input type="hidden" name="w" value="<?php echo $w ?>">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
    <input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
    <input type="hidden" name="sca" value="<?php echo $sca ?>">
    <input type="hidden" name="sfl" value="<?php echo $sfl ?>">
    <input type="hidden" name="stx" value="<?php echo $stx ?>">
    <input type="hidden" name="spt" value="<?php echo $spt ?>">
    <input type="hidden" name="sst" value="<?php echo $sst ?>">
    <input type="hidden" name="sod" value="<?php echo $sod ?>">
    <input type="hidden" name="page" value="<?php echo $page ?>">
    <input type="hidden" name="wr_subject" value="<?php echo $subject ?>">
 
    <!--
    폼메일 입력 구조를 정의합니다.
    입력받을 데이터를 name|항목이름 순으로 입력합니다.
    -->
    <input type="hidden" name="contents_info[]" value="wr_name|성함">
    <input type="hidden" name="contents_info[]" value="wr_email|이메일">
    <input type="hidden" name="contents_info[]" value="wr_1|연락처">
    <input type="hidden" name="contents_info[]" value="wr_2|직책">
    <input type="hidden" name="contents_info[]" value="ca_name|문의종류">
    <input type="hidden" name="contents_info[]" value="wr_content|문의내용">
 
    <section id="formmail-write">
        <?php if($is_admin) {?>
        <a href="<?php echo get_pretty_url($bo_table)?>" class="check-list">문의내역 확인</a>
        <?php }?>
        <div class="form-body">
 
            <div class="form-group col4">
                <label for="wr_name">성함</label>
                <div>
                    <input type="text" name="wr_name" value="<?php echo $member['mb_name']?>" id="wr_name" required class="form-control required" size="8" maxlength="20">
                </div>
                <label for="wr_email">이메일</label>
                <div>
                    <input type="text" name="wr_email" value="<?php echo $member['mb_email']?>" id="wr_email" class="form-control email required" size="50" maxlength="100">
                </div>
            </div>
 
            <div class="form-group col4">
                <label for="wr_1">연락처</label>
                <div>
                    <input type="text" name="wr_1" value="<?php echo $member['mb_hp']?>" id="wr_1" required class="form-control required" size="10" maxlength="20">
                </div>
                <label for="wr_2">직책</label>
                <div>
                    <input type="text" name="wr_2" value="<?php echo $wr_2 ?>" id="wr_2" required class="form-control required" size="10" maxlength="20">
                </div>
            </div>
 
            <?php if ($is_category) { ?>
                <div class="form-group">
                    <label for="ca_name">문의종류</label>
                    <div>
                        <select name="ca_name" id="ca_name" required class="form-control required">
                            <option value="">선택하세요</option>
                            <?php foreach($category_list as $v) {?>
                                <option value="<?php echo $v?>"><?php echo $v?></option>
                            <?php }?>
                        </select>
                    </div>
                </div>
            <?php } ?>
 
            <div class="form-group">
                <label for="wr_content">문의내용</label>
                <div>
                    <textarea id="wr_content" name="wr_content" class="form-control" maxlength="65536" cols="10000" rows="10"><?php echo $wr_content?></textarea>
                </div>
            </div>
 
            <?php for ($i = 0; $is_file && $i < $file_count; $i++) { ?>
                <div class="form-group">
                    <label for="">파일 #<?php echo $i + 1 ?></label>
                    <div>
                        <input type="file" name="bf_file[]" title="파일첨부 <?php echo $i + 1 ?> : 용량 <?php echo $upload_max_filesize ?> 이하만 업로드 가능" class="form-control-file">
                        <?php if ($is_file_content) { ?>
                            <input type="text" name="bf_content[]" value="<?php echo ($w == 'u') ? $file[$i]['bf_content'] : ''; ?>" title="파일 설명을 입력해주세요." class="form-control" size="50">
                        <?php } ?>
                        <?php if ($w == 'u' && $file[$i]['file']) { ?>
                            <input type="checkbox" id="bf_file_del<?php echo $i ?>" name="bf_file_del[<?php echo $i; ?>]" value="1"> <label for="bf_file_del<?php echo $i ?>"><?php echo $file[$i]['source'] . '(' . $file[$i]['size'] . ')'; ?> 파일 삭제</label>
                        <?php } ?>
                    </div>
                </div>
            <?php } ?>
 
            <?php if ($is_use_captcha) { //자동등록방지  ?>
            <div class="form-group">
                <label for="">자동등록<br/>방지</label>
                <div><?php echo $captcha_html?></div>
            </div>
            <?php } ?>
        </div>
 
        <div class="privacy-of-use">
            <?php echo $privacy_html?>
        </div>
        <div class="privacy-of-use-check">
            <label><input type="checkbox" class="required" required/> 개인정보 처리방침에 동의합니다.</label>
        </div>
 
        <div class="form-footer">
            <button type="submit" id="btn_submit" class="btn_submit btn btn-primary">문의하기</button>
        </div>
 
    </section>
</form>
 
<script type="text/javascript">
    function fwrite_submit(f) {
        //=================================
        //파일 검사
        var error=fileSizeCheck();
        if(error!=""){
            return false;
        }        
        //----------------------------------
        let subject = "";
        let content = "";
        $.ajax({
            url: g5_bbs_url + "/ajax.filter.php",
            type: "POST",
            data: {
                "subject": f.wr_subject.value,
                "content": f.wr_content.value
            },
            dataType: "json",
            async: false,
            cache: false,
            success: function(data, textStatus) {
                subject = data.subject;
                content = data.content;
            }
        });
 
        if (subject) {
            alert("제목에 금지단어('" + subject + "')가 포함되어있습니다");
            f.wr_subject.focus();
            return false;
        }
 
        if (content) {
            alert("내용에 금지단어('" + content + "')가 포함되어있습니다");
            if (typeof(ed_wr_content) != "undefined")
                ed_wr_content.returnFalse();
            else
                f.wr_content.focus();
            return false;
        }
        /* 이부분 추가 시작 */
    //파일첨부 확장자 소스 (jquery)
 
      var Format= "\.(jpg|gif|pdf|ppt|pptx|png)$"; //지정확장자 소스
 
for(var i = 0; i < $("input[type=file]").length; i++){
 
    if($("input[type=file]").val() == ""){ //파일 올린 내용이 있는지 검사 중에 존재 하지 않는다면
 
return true;
 
      }else { //파일 올린 내용이 있는지 검사 중에 존재 한다면
 
          if((new RegExp(Format, "i")).test($("input[type=file]").eq(i).val())){ //지정된 확장자가 맞을면 정상
 
            return true;
 
          }else {  //지정된 확장자가 틀리면 오류 메세지 발생
 
alert("이미지 파일(jpg|gif|pdf|ppt|png)만 첨부하실 수 있습니다.");
 
return false;
 
          }
 
    }
 
}
 
/* 이부분 추가 끝 */
        // 캡챠 사용시 자바스크립트에서 입력된 캡챠를 검사함
        <?php echo $captcha_js?>
 
        document.getElementById("btn_submit").disabled = "disabled";
 
        return true;
    }
   
</script>
<script type="text/javascript">
    <!--
        function fileSizeCheck() {
        //=================================
        //파일 용량 검사
        var file_max_size = <?php echo intval($board[bo_upload_size]);?> ;
        if(file_max_size<=0){
            return "";
        }
        if (!window.FileReader) {//file reader 을 제공하지 않습니다 검사안함
            return "";
        }
        var error_msg="";
        var new_line="";
        //해당 파일 루프를 돈다
        jQuery("#bo_w input[type='file']").each(function(){
            var input, file;
            //업로드 자료만 확인
            if(jQuery(this).val()!="")
            {
                var input_id=jQuery(this).attr("id");
                if(input_id){                
                    input = document.getElementById(input_id);
                    if (!input) {
                        return ""; //업로드 파일을 찾을수 없음
                    }
                    else if (!input.files) {
                        return ""; //file reader 제공안함
                    }
                    else if (!input.files[0]) {
                        return ""; //파일이 없음
                    }
                    else {
                        file = input.files[0];
                        if(file.size>file_max_size){
                            error_msg=error_msg+new_line+ file.name + "의 사이즈는 " + file.size + "bytes로  "+file_max_size+"bytes를 초과하셨습니다";
                            new_line="\n";
                        }
                    }
                }
            }
        });
        if(error_msg!=""){
            alert(error_msg);
            return "error";
        }
        return "";
    }
    //-->
    </script>

이 질문에 댓글 쓰기 :

답변 2

아래의 내용을 참고해 보시겠어요~

 

function fileSizeCheck() {
    //=================================
    //파일 용량 검사
    **var file_max_size = <?php echo intval($board[bo_upload_size]);?> * 1024;**
    if(file_max_size<=0){
        return "";
    }
    if (!window.FileReader) {//file reader 을 제공하지 않습니다 검사안함
        return "";
    }
    var error_msg="";
    var new_line="";
    //해당 파일 루프를 돈다
    jQuery("#bo_w input[type='file']").each(function(){
        var input, file;
        //업로드 자료만 확인
        if(jQuery(this).val()!="")
        {
            var input_id=jQuery(this).attr("id");
            if(input_id){                
                input = document.getElementById(input_id);
                if (!input) {
                    return ""; //업로드 파일을 찾을수 없음
                }
                else if (!input.files) {
                    return ""; //file reader 제공안함
                }
                else if (!input.files[0]) {
                    return ""; //파일이 없음
                }
                else {
                    file = input.files[0];
                    if(file.size>file_max_size){
                        error_msg=error_msg+new_line+ file.name + "의 사이즈는 " + (file.size/1024).toFixed(2) + "Kbytes로  "+file_max_size+"Kbytes를 초과하셨습니다";
                        new_line="\n";
                    }
                }
            }
        }
    });
    if(error_msg!=""){
        alert(error_msg);
        return "error";
    }
    return "";
}
 

 

 

 

    if (!window.FileReader) {//file reader 을 제공하지 않습니다 검사안함
        return "";
    }

===> 이 부분때문에 그냥 넘어갈 가능성도 커보입니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 82
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT