명랑폐인님 소스중에 글등록 함수인데 물어 볼게 있어요

명랑폐인님 소스중에 글등록 함수인데 물어 볼게 있어요

QA

명랑폐인님 소스중에 글등록 함수인데 물어 볼게 있어요

본문


/**
 * 그누보드 게시물 등록 함수.
  *  $bo_table 게시판명 ex) freeboard
 *  $subject  게시물 제목
 *  $content 게시물 내용
 *  array $files 업로드할 파일 경로 배열, 물리적 경로입력
 *              ex /home/account/www/data/uploads/images1.jpg,,,,
 *
 */
function board_write($bo_table, $subject, $content, $files=array()) {
    global $g5, $config;
    $write_table = "g5_write_{$bo_table}";
    $wr_num = get_next_num($write_table);
    $wr_reply = '';
    $ca_name = "";
    $html = ""; $secret=""; $mail = "";
    $wr_subject = $subject;
    $wr_content = $content;
    $wr_link1 = "";
    $wr_link2 = "";
    $mb_id = "admin";
    $wr_name = "관리자";
    $wr_email = "";
    $sql = " insert into $write_table
                set wr_num = '$wr_num',
                     wr_reply = '$wr_reply',
                     wr_comment = 0,
                     ca_name = '$ca_name',
                     wr_option = '$html,$secret,$mail',
                     wr_subject = '$wr_subject',
                     wr_content = '$wr_content',
                     wr_link1 = '$wr_link1',
                     wr_link2 = '$wr_link2',
                     wr_link1_hit = 0,
                     wr_link2_hit = 0,
                     wr_hit = 0,
                     wr_good = 0,
                     wr_nogood = 0,
                     mb_id = '$mb_id',
                     wr_password = '',
                     wr_name = '$wr_name',
                     wr_email = '$wr_email',
                     wr_homepage = '',
                     wr_datetime = '".G5_TIME_YMDHIS."',
                     wr_last = '".G5_TIME_YMDHIS."',
                     wr_ip = '{$_SERVER['REMOTE_ADDR']}',
                     wr_1 = '',
                     wr_2 = '',
                     wr_3 = '',
                     wr_4 = '',
                     wr_5 = '',
                     wr_6 = '',
                     wr_7 = '',
                     wr_8 = '',
                     wr_9 = '',
                     wr_10 = '' ";
    sql_query($sql);
    $wr_id = sql_insert_id();
    // 부모 아이디에 UPDATE
    sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");
    // 새글 INSERT
    sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$wr_id}', '{$wr_id}', '".G5_TIME_YMDHIS."', '$mb_id' ) ");
    // 게시글 1 증가
    sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}'");
    // 파일개수 체크
    $file_count   = 0;
    $upload_count = count($files);
    for ($i=0; $i<$upload_count; $i++) {
        if($files[$i] && file_exists($files[$i]))
            $file_count++;
    }
    // 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
    (G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);
    @chmod(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);
    $chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));
    // 가변 파일 업로드
    $file_upload_msg = '';
    $upload = array();
    for ($i=0; $i<count($files); $i++) {
        $upload[$i]['file']     = '';
        $upload[$i]['source']   = '';
        $upload[$i]['filesize'] = 0;
        $upload[$i]['image']    = array();
        $upload[$i]['image'][0] = '';
        $upload[$i]['image'][1] = '';
        $upload[$i]['image'][2] = '';
        $upload[$i]['del_check'] = false;
        $tmp_file  = $files[$i];
        $filesize  = filesize($files[$i]);
        $filename  = basename($files[$i]);
        $filename  = get_safe_filename($filename);
        if (file_exists($tmp_file)) {
            //=================================================================\
            // 090714
            // 이미지나 플래시 파일에 악성코드를 심어 업로드 하는 경우를 방지
            // 에러메세지는 출력하지 않는다.
            //-----------------------------------------------------------------
            $timg = @getimagesize($tmp_file);
            // image type
            if ( preg_match("/\.({$config['cf_image_extension']})$/i", $filename) ||
                preg_match("/\.({$config['cf_flash_extension']})$/i", $filename) ) {
                if ($timg['2'] < 1 || $timg['2'] > 16)
                    continue;
            }
            //=================================================================
            $upload[$i]['image'] = $timg;
            // 프로그램 원래 파일명
            $upload[$i]['source'] = $filename;
            $upload[$i]['filesize'] = $filesize;
            // 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함
            $filename = preg_replace("/\.(php|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i", "$0-x", $filename);
            shuffle($chars_array);
            $shuffle = implode('', $chars_array);
            // 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
            $upload[$i]['file'] = abs(ip2long($_SERVER['REMOTE_ADDR'])).'_'.substr($shuffle,0,8).'_'.replace_filename($filename);
            $dest_file = G5_DATA_PATH.'/file/'.$bo_table.'/'.$upload[$i]['file'];
            // 업로드가 안된다면 에러메세지 출력하고 죽어버립니다.
            $error_code = copy($tmp_file, $dest_file) or die("upload error");
            // 올라간 파일의 퍼미션을 변경합니다.
            chmod($dest_file, G5_FILE_PERMISSION);
        }
    }
    // 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
    for ($i=0; $i<count($upload); $i++)
    {
        if (!get_magic_quotes_gpc()) {
            $upload[$i]['source'] = addslashes($upload[$i]['source']);
        }
        $sql = " insert into {$g5['board_file_table']}
                set bo_table = '{$bo_table}',
                     wr_id = '{$wr_id}',
                     bf_no = '{$i}',
                     bf_source = '{$upload[$i]['source']}',
                     bf_file = '{$upload[$i]['file']}',
                     bf_content = '',
                     bf_download = 0,
                     bf_filesize = '{$upload[$i]['filesize']}',
                     bf_width = '{$upload[$i]['image']['0']}',
                     bf_height = '{$upload[$i]['image']['1']}',
                     bf_type = '{$upload[$i]['image']['2']}',
                     bf_datetime = '".G5_TIME_YMDHIS."' ";
        sql_query($sql);
    }
    // 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서
    // 파일 정보가 없다면 테이블의 내용을 삭제합니다.
    $row = sql_fetch(" select max(bf_no) as max_bf_no from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");
    for ($i=(int)$row['max_bf_no']; $i>=0; $i--)
    {
        $row2 = sql_fetch(" select bf_file from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");
        // 정보가 있다면 빠집니다.
        if ($row2['bf_file']) break;
        // 그렇지 않다면 정보를 삭제합니다.
        sql_query(" delete from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");
    }
    // 파일의 개수를 게시물에 업데이트 한다.
    $row = sql_fetch(" select count(*) as cnt from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");
    sql_query(" update {$write_table} set wr_file = '{$row['cnt']}' where wr_id = '{$wr_id}' ");
}

 

명랑폐인님의 "게시판 파싱후 글등록 처리 함수" 코드인데요....

여기에서 이미지를 받아오는 처음 부분은 어디인가요?

c\abcd.gif 라는 이미지를 글과 같이 업로드 할때 , 위에 코드에서 c\abcd.gif 이 이미지를 어느 부분에서 처음 처리를 하나요?

이 질문에 댓글 쓰기 :

답변 2

질문의 함수를 사용할 때 게시판 테이블명, 제목, 내용, 파일 목록 배열을 지정하니까 처음부터겠죠?

 

아래처럼 함수 사용하면,

board_write('게시판 테이블명', '제목', '내용', ['/home/test/file1', '/home/test/file2', '/home/test/file3']);

함수 내의 아래 부분에서 파일 반복 처리 시작.

    $upload = array();
    for ($i=0; $i<count($files); $i++) {

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

회원로그인

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