게시글 첨부파일 동시등록

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
게시글 첨부파일 동시등록

QA

게시글 첨부파일 동시등록

본문

안녕하세요. 관련 내용 마지막 질문입니다.

 

게시글이 동시등록 되는 것은 어찌어찌 성공했습니다. 그런데 첨부파일이 문제입니다.

bbs/move_update.php와 write_update.php를 참고해서 파일부분을 넣어봤는데 안됩니다. 


  <?php if ($w =='' && $bo_table =='dailydakku')
  {
      $table_copy = "fullcalendar"; // 복사 게시판id
      $write_table_copy = $g5['write_prefix'] . $table_copy;
      $wr_num_copy = get_next_num($write_table_copy);
      $sql_copy = " insert into $write_table_copy
                  set wr_num = '$wr_num_copy',
                       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 = '{$member['mb_id']}',
                       wr_password = '$wr_password',
                       wr_name = '$wr_name',
                       wr_email = '$wr_email',
                       wr_homepage = '$wr_homepage',
                       wr_datetime = '".G5_TIME_YMDHIS."',
                       wr_file = '$wr_file',
                       wr_last = '".G5_TIME_YMD."',
                       wr_ip = '{$_SERVER['REMOTE_ADDR']}',
                       wr_1 = '".G5_TIME_YMD."',
                       wr_2 = '".G5_TIME_YMD."',
                       wr_3 = '$wr_3',
                       wr_4 = '$wr_4',
                       wr_5 = '$wr_5',
                       wr_6 = '$wr_6',
                       wr_7 = '$wr_7',
                       wr_8 = '$wr_8',
                       wr_9 = '$wr_9',
                       wr_10 = '$wr_10' ";
      sql_query($sql_copy);
      $wr_id_copy = sql_insert_id();
      // 부모 아이디에 UPDATE
      sql_query(" update $write_table_copy set wr_parent = '$wr_id_copy' where wr_id = '$wr_id_copy' ");
      // 새글 INSERT
      sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$table_copy}', '{$wr_id_copy}', '{$wr_id_copy}', '".G5_TIME_YMDHIS."', '{$member['mb_id']}' ) ");
      // 게시글 1 증가
      sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$table_copy}'");

      // 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
      (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();
      if(isset($_FILES['bf_file']['name']) && is_array($_FILES['bf_file']['name'])) {
          for ($i=0; $i<count($_FILES['bf_file']['name']); $i++) {
              $upload[$i]['file']     = '';
              $upload[$i]['source']   = '';
              $upload[$i]['filesize'] = 0;
              $upload[$i]['image']    = array();
              $upload[$i]['image'][0] = 0;
              $upload[$i]['image'][1] = 0;
              $upload[$i]['image'][2] = 0;
              $upload[$i]['fileurl'] = '';
              $upload[$i]['thumburl'] = '';
              $upload[$i]['storage'] = '';
              // 삭제에 체크가 되어있다면 파일을 삭제합니다.
              if (isset($_POST['bf_file_del'][$i]) && $_POST['bf_file_del'][$i]) {
                  $upload[$i]['del_check'] = true;
                  $row = sql_fetch(" select * from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");
                  $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '', $row['bf_file']), $row);
                  if( file_exists($delete_file) ){
                      @unlink($delete_file);
                  }
                  // 썸네일삭제
                  if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) {
                      delete_board_thumbnail($bo_table, $row['bf_file']);
                  }
              }
              else
                  $upload[$i]['del_check'] = false;
              $tmp_file  = $_FILES['bf_file']['tmp_name'][$i];
              $filesize  = $_FILES['bf_file']['size'][$i];
              $filename  = $_FILES['bf_file']['name'][$i];
              $filename  = get_safe_filename($filename);
              // 서버에 설정된 값보다 큰파일을 업로드 한다면
              if ($filename) {
                  if ($_FILES['bf_file']['error'][$i] == 1) {
                      $file_upload_msg .= '\"'.$filename.'\" 파일의 용량이 서버에 설정('.$upload_max_filesize.')된 값보다 크므로 업로드 할 수 없습니다.\\n';
                      continue;
                  }
                  else if ($_FILES['bf_file']['error'][$i] != 0) {
                      $file_upload_msg .= '\"'.$filename.'\" 파일이 정상적으로 업로드 되지 않았습니다.\\n';
                      continue;
                  }
              }
              if (is_uploaded_file($tmp_file)) {
                  // 관리자가 아니면서 설정한 업로드 사이즈보다 크다면 건너뜀
                  if (!$is_admin && $filesize > $board['bo_upload_size']) {
                      $file_upload_msg .= '\"'.$filename.'\" 파일의 용량('.number_format($filesize).' 바이트)이 게시판에 설정('.number_format($board['bo_upload_size']).' 바이트)된 값보다 크므로 업로드 하지 않습니다.\\n';
                      continue;
                  }
                  //=================================================================\
                  // 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'] > 18)
                          continue;
                  }
                  //=================================================================
                  $upload[$i]['image'] = $timg;
                  // 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정
                  if ($w == 'u') {
                      // 존재하는 파일이 있다면 삭제합니다.
                      $row = sql_fetch(" select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
                      if(isset($row['bf_file']) && $row['bf_file']){
                          $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '', $row['bf_file']), $row);
                          if( file_exists($delete_file) ){
                              @unlink(G5_DATA_PATH.'/file/'.$bo_table.'/'.$row['bf_file']);
                          }
                          // 이미지파일이면 썸네일삭제
                          if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) {
                              delete_board_thumbnail($bo_table, $row['bf_file']);
                          }
                      }
                  }
                  // 프로그램 원래 파일명
                  $upload[$i]['source'] = $filename;
                  $upload[$i]['filesize'] = $filesize;
                  // 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함
                  $filename = preg_replace("/\.(php|pht|phtm|htm|cgi|pl|exe|jsp|asp|inc|phar)/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 = move_uploaded_file($tmp_file, $dest_file) or die($_FILES['bf_file']['error'][$i]);
                  // 올라간 파일의 퍼미션을 변경합니다.
                  chmod($dest_file, G5_FILE_PERMISSION);
                  $dest_file = run_replace('write_update_upload_file', $dest_file, $board, $wr_id, $w);
                  $upload[$i] = run_replace('write_update_upload_array', $upload[$i], $dest_file, $board, $wr_id, $w);
              }
          }   // end for
      }   // end if
      // 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
      for ($i=0; $i<count($upload); $i++)
      {
          $upload[$i]['source'] = sql_real_escape_string($upload[$i]['source']);
          $bf_content[$i] = isset($bf_content[$i]) ? sql_real_escape_string($bf_content[$i]) : '';
          $bf_width = isset($upload[$i]['image'][0]) ? (int) $upload[$i]['image'][0] : 0;
          $bf_height = isset($upload[$i]['image'][1]) ? (int) $upload[$i]['image'][1] : 0;
          $bf_type = isset($upload[$i]['image'][2]) ? (int) $upload[$i]['image'][2] : 0;
          $row = sql_fetch(" select count(*) as cnt from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");
          if ($row['cnt'])
          {
              // 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다.
              // 그렇지 않다면 내용만 업데이트 합니다.
              if ($upload[$i]['del_check'] || $upload[$i]['file'])
              {
                  $sql = " update {$g5['board_file_table']}
                              set bf_source = '{$upload[$i]['source']}',
                                   bf_file = '{$upload[$i]['file']}',
                                   bf_content = '{$bf_content[$i]}',
                                   bf_fileurl = '{$upload[$i]['fileurl']}',
                                   bf_thumburl = '{$upload[$i]['thumburl']}',
                                   bf_storage = '{$upload[$i]['storage']}',
                                   bf_filesize = '".(int)$upload[$i]['filesize']."',
                                   bf_width = '".$bf_width."',
                                   bf_height = '".$bf_height."',
                                   bf_type = '".$bf_type."',
                                   bf_datetime = '".G5_TIME_YMDHIS."'
                            where bo_table = '{$bo_table}'
                                      and wr_id = '{$wr_id}'
                                      and bf_no = '{$i}' ";
                  sql_query($sql);
              }
              else
              {
                  $sql = " update {$g5['board_file_table']}
                              set bf_content = '{$bf_content[$i]}'
                              where bo_table = '{$bo_table}'
                                        and wr_id = '{$wr_id}'
                                        and bf_no = '{$i}' ";
                  sql_query($sql);
              }
          }
          else
          {
              $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_content[$i]}',
                               bf_fileurl = '{$upload[$i]['fileurl']}',
                               bf_thumburl = '{$upload[$i]['thumburl']}',
                               bf_storage = '{$upload[$i]['storage']}',
                               bf_download = 0,
                               bf_filesize = '".(int)$upload[$i]['filesize']."',
                               bf_width = '".$bf_width."',
                               bf_height = '".$bf_height."',
                               bf_type = '".$bf_type."',
                               bf_datetime = '".G5_TIME_YMDHIS."' ";
              sql_query($sql);
              run_event('write_update_file_insert', $bo_table, $wr_id, $upload[$i], $w);
          }
      }
      // 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서
      // 파일 정보가 없다면 테이블의 내용을 삭제합니다.
      $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 (isset($row2['bf_file']) && $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}' ");
      // 자동저장된 레코드를 삭제한다.
      sql_query(" delete from {$g5['autosave_table']} where as_uid = '{$uid}' ");
      // 복사게시판 최신글 캐시갱신
      delete_cache_latest($table_copy);
  } ?>

동시등록 코드부분 입니다.

동시등록할때 첨부파일까지 등록할 수 있는 방법을 알려주시면 감사하겠습니다,,

이 질문에 댓글 쓰기 :

답변 2

방법이 여러가지인데요.

1. 게시물 복사를 DB에서 실제 로 복사하지 않고 view 등의 다른 방법을 쓴다.

2. 필요한 곳에서 get_file() 이용한다.

3. g5_board_file에서 원본 게시물 레코드를 bo_table에 맞게 복사하고

첨부 파일은 복사 또는 링크를 건다.

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

회원로그인

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