목록에서 댓글 작성 정녕 안 되는 걸까요..?
안녕하세요.
게시판 목록에서 댓글 작성이 되게 하는 걸 시도하고 있습니다.
근데 '올바른 방법으로 이용해 주십시오'라는 문구가 계속 떠요..
비회원까진 바라지도 않는데, 로그인해도 매한가지네요..
AI의 도움도 빌려봤는데... 크흠....ㅠㅠ
고수님들 부디 도와주시면 감사하겠습니다..ㅜㅜㅜ
1번째 버전
2번째 버전
3번째 버전
4번째 버전
5번째 버전
<?php
for ($i=0; $i<count($list); $i++) {
// 댓글을 쓸 권한 세션을 강제로 생성
set_session('ss_write_'.$bo_table.'_'.$list[$i]['wr_id'], true);
<button type="button"
class="btn_submit"
onclick="flist_comment_submit('<?php echo $list[$i]['wr_id'] ?>', '<?php echo $list_token; ?>');">등록</button>
<script>
function flist_comment_submit(wr_id, token) {
<?php if (!$is_member) { ?>
alert("로그인 후 이용 가능합니다."); return;
<?php } ?>
var wr_content = document.getElementById("save_comment_" + wr_id).value;
if (!wr_content) {
alert("내용을 입력하세요."); return;
}
var form = document.createElement("form");
form.method = "post";
form.action = "<?php echo G5_BBS_URL; ?>/write_comment_update.php";
var params = {
"w": "c",
"bo_table": "<?php echo $bo_table ?>",
"wr_id": wr_id,
"token": token,
"wr_content": wr_content,
"wr_secret": "0"
};
for (var key in params) {
var input = document.createElement("input");
input.type = "hidden";
input.name = key;
input.value = params[key];
form.appendChild(input);
}
document.body.appendChild(form);
form.submit();
}
</script>
답변 2개
3시간 전
아래는 제가 예전에 만든 간편 글등록 펑션입니다.
폼전송을 해도되고 ajax 로 비동기 처리해도 됩니다.
Copy
<?php include_once('./_common.php');
/**
* 그누보드 게시물 등록 함수.
* @param $bo_table 게시판명 ex) freeboard
* @param $subject 게시물 제목
* @param $content 게시물 내용
* @param array $files 업로드할 파일 경로 배열, 물리적 경로입력 (ex /home/account/www/data/uploads/images1.jpg,,,,)
*
*/
function board_write($mbid, $mbname, $bo_table, $subject, $content, $wr1, $wr2, $wr3, $wr4, $wr5, $wr6, $wr7, $wr8, $wr9, $wr10, $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 = $mbid;
$wr_name = $mbname;
$wr_email = "";
$wr_1 = $wr1;
$wr_2 = $wr2;
$wr_3 = $wr3;
$wr_4 = $wr4;
$wr_5 = $wr5;
$wr_6 = $wr6;
$wr_7 = $wr7;
$wr_8 = $wr8;
$wr_9 = $wr9;
$wr_10 = $wr10;
$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++;
}
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
@mkdir(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}' ");
$result = 'ok';
}
echo board_write('adpro','애드프로','sample','테스트글등록','본문','','','','','','','','','','','');
if($result = 'ok'){
echo '등록이 완료되었습니다.';
}
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
4시간 전
<?php echo G5_BBS_URL; ?>/write_comment_update.php 이것말고
write_comment_update2.php 처럼 파일을 따로 만든 후에
필요 없는 부분은 삭제 하고 해 보세요...
단순하게 내용만 넣어서는 안됩니다.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인