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

게시글 첨부파일 동시등록 채택완료

밍구9 3년 전 조회 2,730

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

 

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

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

</p>

<p>  <?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);</p>

<p>      $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);</p>

<p>      $wr_id_copy = sql_insert_id();</p>

<p>      // 부모 아이디에 UPDATE

      sql_query(" update $write_table_copy set wr_parent = '$wr_id_copy' where wr_id = '$wr_id_copy' ");</p>

<p>      // 새글 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']}' ) ");</p>

<p>      // 게시글 1 증가

      sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$table_copy}'");</p>

<p>

      // 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)

      @mkdir(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);

      @chmod(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);</p>

<p>      $chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));</p>

<p>      // 가변 파일 업로드

      $file_upload_msg = '';

      $upload = array();</p>

<p>      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'] = '';</p>

<p>              // 삭제에 체크가 되어있다면 파일을 삭제합니다.

              if (isset($_POST['bf_file_del'][$i]) && $_POST['bf_file_del'][$i]) {

                  $upload[$i]['del_check'] = true;</p>

<p>                  $row = sql_fetch(" select * from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");</p>

<p>                  $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;</p>

<p>              $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);</p>

<p>              // 서버에 설정된 값보다 큰파일을 업로드 한다면

              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;

                  }

              }</p>

<p>              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;

                  }</p>

<p>                  //=================================================================\

                  // 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;

                  }

                  //=================================================================</p>

<p>                  $upload[$i]['image'] = $timg;</p>

<p>                  // 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' ");</p>

<p>                      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']);

                          }

                      }

                  }</p>

<p>                  // 프로그램 원래 파일명

                  $upload[$i]['source'] = $filename;

                  $upload[$i]['filesize'] = $filesize;</p>

<p>                  // 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함

                  $filename = preg_replace("/\.(php|pht|phtm|htm|cgi|pl|exe|jsp|asp|inc|phar)/i", "$0-x", $filename);</p>

<p>                  shuffle($chars_array);

                  $shuffle = implode('', $chars_array);</p>

<p>                  // 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)

                  $upload[$i]['file'] = abs(ip2long($_SERVER['REMOTE_ADDR'])).'_'.substr($shuffle,0,8).'_'.replace_filename($filename);</p>

<p>                  $dest_file = G5_DATA_PATH.'/file/'.$bo_table.'/'.$upload[$i]['file'];</p>

<p>                  // 업로드가 안된다면 에러메세지 출력하고 죽어버립니다.

                  $error_code = move_uploaded_file($tmp_file, $dest_file) or die($_FILES['bf_file']['error'][$i]);</p>

<p>                  // 올라간 파일의 퍼미션을 변경합니다.

                  chmod($dest_file, G5_FILE_PERMISSION);</p>

<p>                  $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</p>

<p>      // 나중에 테이블에 저장하는 이유는 $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;</p>

<p>          $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);</p>

<p>              run_event('write_update_file_insert', $bo_table, $wr_id, $upload[$i], $w);

          }

      }</p>

<p>      // 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서

      // 파일 정보가 없다면 테이블의 내용을 삭제합니다.

      $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}' ");</p>

<p>          // 정보가 있다면 빠집니다.

          if (isset($row2['bf_file']) && $row2['bf_file']) break;</p>

<p>          // 그렇지 않다면 정보를 삭제합니다.

          sql_query(" delete from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");

      }</p>

<p>      // 파일의 개수를 게시물에 업데이트 한다.

      $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}' ");</p>

<p>      // 자동저장된 레코드를 삭제한다.

      sql_query(" delete from {$g5['autosave_table']} where as_uid = '{$uid}' ");</p>

<p>      // 복사게시판 최신글 캐시갱신

      delete_cache_latest($table_copy);</p>

<p>  } ?></p>

<p>

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

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

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

답변 2개

채택된 답변
+20 포인트

방법이 여러가지인데요.

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

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

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

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

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

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

print_r($_file); 로 디버깅 해보셨나요?

파일이 나오나요?

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

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

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

로그인