코멘트 입력시 파일첨부도 가능할까요? 정보
코멘트 입력시 파일첨부도 가능할까요?본문
코멘트 작성시 ...파일 첨부도 가능할까요?
지금 자게같은곳은 이미지를 보여줄때 [img src=]이런식인데...파일을 첨부를 하면 더 좋을것 같아서 문득 궁금증이 생깁니다.
가능하다면 어떤식으로 처리를 해야하는지 사알짝만 알려주세요~^^
댓글 전체
사무실 출근해서 모니터링 하겠습니다..ㅜ.ㅜ
미리 감사합니다.
미리 감사합니다.
그누보드는 코맨트에도 wr_id 를 부여하기 때문에 파일올리기는 어렵지 않습니다.
write_comment_update.skin.php 에서 파일올리는 작업을 하면 됩니다.
$comment_id 가 wr_id 가 되며 이걸 파일테이블에 insert 하면 됩니다.
대강의 프로세스는 이렇습니다.
write_comment_update.skin.php 에서 파일올리는 작업을 하면 됩니다.
$comment_id 가 wr_id 가 되며 이걸 파일테이블에 insert 하면 됩니다.
대강의 프로세스는 이렇습니다.
코멘트 전용 파일저장 테이블을 따로 생성을 해야되겠네요..
그럴필요 없습니다.
$g4[board_file_table] 에 그대로 저장하면 됩니다.
$g4[board_file_table] 에 그대로 저장하면 됩니다.
write.update 에서.. 아래와 같은것만 코멘트 업데이트에 넣어봤습니다...
결과는...코멘트 글은 올라오는데 화일이 안올라와요 ㅜ.ㅜ
<?
// 가변 파일 업로드
$file_upload_msg = "";
$upload = array();
for ($i=0; $i<count($_FILES[bf_file][name]); $i++)
{
// 삭제에 체크가 되어있다면 파일을 삭제합니다.
if ($_POST[bf_file_del][$i])
{
$upload[$i][del_check] = true;
$row = sql_fetch(" select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/file/$bo_table/$row[bf_file]");
}
else
$upload[$i][del_check] = false;
$tmp_file = $_FILES[bf_file][tmp_name][$i];
$filename = $_FILES[bf_file][name][$i];
$filesize = $_FILES[bf_file][size][$i];
// 서버에 설정된 값보다 큰파일을 업로드 한다면
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;
}
// 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정
if ($w == 'u')
{
// 존재하는 파일이 있다면 삭제합니다.
$row = sql_fetch(" select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/file/$bo_table/$row[bf_file]");
}
// 프로그램 원래 파일명
$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);
// 접미사를 붙인 파일명
//$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr(md5(uniqid($g4[server_time])),0,8).'_'.urlencode($filename);
// 달빛온도님 수정 : 한글파일은 urlencode($filename) 처리를 할경우 '%'를 붙여주게 되는데 '%'표시는 미디어플레이어가 인식을 못하기 때문에 재생이 안됩니다. 그래서 변경한 파일명에서 '%'부분을 빼주면 해결됩니다.
$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr(md5(uniqid($g4[server_time])),0,8).'_'.str_replace('%', '', urlencode($filename));
$dest_file = "$g4[path]/data/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, 0606);
$upload[$i][image] = @getimagesize($dest_file);
}
}
//------------------------------------------------------------------------------
// 가변 파일 업로드
// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
for ($i=0; $i<count($upload); $i++)
{
$row = sql_fetch(" select count(*) as cnt from $g4[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 $g4[board_file_table]
set bf_source = '{$upload[$i][source]}',
bf_file = '{$upload[$i][file]}',
bf_content = '{$bf_content[$i]}',
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 = '$g4[time_ymdhis]'
where bo_table = '$bo_table'
and wr_id = '$wr_id'
and bf_no = '$i' ";
sql_query($sql);
}
else
{
$sql = " update $g4[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 $g4[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_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 = '$g4[time_ymdhis]' ";
sql_query($sql);
}
}
// 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서
// 파일 정보가 없다면 테이블의 내용을 삭제합니다.
$row = sql_fetch(" select max(bf_no) as max_bf_no from $g4[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 $g4[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 $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
}
//------------------------------------------------------------------------------
if ($file_upload_msg)
alert($file_upload_msg, "./board.php?bo_table=$bo_table&wr_id=$wr_id&page=$page" . $qstr);
else
goto_url("./board.php?bo_table=$bo_table&wr_id=$wr_id&page=$page" . $qstr);
?>
결과는...코멘트 글은 올라오는데 화일이 안올라와요 ㅜ.ㅜ
<?
// 가변 파일 업로드
$file_upload_msg = "";
$upload = array();
for ($i=0; $i<count($_FILES[bf_file][name]); $i++)
{
// 삭제에 체크가 되어있다면 파일을 삭제합니다.
if ($_POST[bf_file_del][$i])
{
$upload[$i][del_check] = true;
$row = sql_fetch(" select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/file/$bo_table/$row[bf_file]");
}
else
$upload[$i][del_check] = false;
$tmp_file = $_FILES[bf_file][tmp_name][$i];
$filename = $_FILES[bf_file][name][$i];
$filesize = $_FILES[bf_file][size][$i];
// 서버에 설정된 값보다 큰파일을 업로드 한다면
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;
}
// 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정
if ($w == 'u')
{
// 존재하는 파일이 있다면 삭제합니다.
$row = sql_fetch(" select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/file/$bo_table/$row[bf_file]");
}
// 프로그램 원래 파일명
$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);
// 접미사를 붙인 파일명
//$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr(md5(uniqid($g4[server_time])),0,8).'_'.urlencode($filename);
// 달빛온도님 수정 : 한글파일은 urlencode($filename) 처리를 할경우 '%'를 붙여주게 되는데 '%'표시는 미디어플레이어가 인식을 못하기 때문에 재생이 안됩니다. 그래서 변경한 파일명에서 '%'부분을 빼주면 해결됩니다.
$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr(md5(uniqid($g4[server_time])),0,8).'_'.str_replace('%', '', urlencode($filename));
$dest_file = "$g4[path]/data/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, 0606);
$upload[$i][image] = @getimagesize($dest_file);
}
}
//------------------------------------------------------------------------------
// 가변 파일 업로드
// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
for ($i=0; $i<count($upload); $i++)
{
$row = sql_fetch(" select count(*) as cnt from $g4[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 $g4[board_file_table]
set bf_source = '{$upload[$i][source]}',
bf_file = '{$upload[$i][file]}',
bf_content = '{$bf_content[$i]}',
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 = '$g4[time_ymdhis]'
where bo_table = '$bo_table'
and wr_id = '$wr_id'
and bf_no = '$i' ";
sql_query($sql);
}
else
{
$sql = " update $g4[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 $g4[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_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 = '$g4[time_ymdhis]' ";
sql_query($sql);
}
}
// 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서
// 파일 정보가 없다면 테이블의 내용을 삭제합니다.
$row = sql_fetch(" select max(bf_no) as max_bf_no from $g4[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 $g4[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 $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");
}
//------------------------------------------------------------------------------
if ($file_upload_msg)
alert($file_upload_msg, "./board.php?bo_table=$bo_table&wr_id=$wr_id&page=$page" . $qstr);
else
goto_url("./board.php?bo_table=$bo_table&wr_id=$wr_id&page=$page" . $qstr);
?>
심심해서 저도 만들어 봤습니다.
대충 만든거니 살은 직접 붙이세요.
basic 스킨기준입니다.
view_comment.skin.php 의 comment form 에 enctype="multipart/form-data" 추가,
적당한 위치에 <input type=file name=comment_file> 추가,
write_comment_update.skin.php 에
<?
if(is_uploaded_file($comment_file)) {
$tmp_file = $_FILES[comment_file][tmp_name];
$filename = $_FILES[comment_file][name];
$filesize = $_FILES[comment_file][size];
$dest = "$g4[path]/data/file/$bo_table/".$HTTP_POST_FILES[comment_file][name];
move_uploaded_file($HTTP_POST_FILES[comment_file][tmp_name], "$dest");
$imagesize = @getimagesize($dest);
$sql = " insert into $g4[board_file_table]
set bo_table = '$bo_table',
wr_id = '$comment_id',
bf_no = '0',
bf_source = '$filename',
bf_file = '$filename',
bf_content = '{$bf_content}',
bf_download = 0,
bf_filesize = '$filesize',
bf_width = '{$imagesize[0]}',
bf_height = '{$imagesize[1]}',
bf_type = '{$imagesize[2]}',
bf_datetime = '$g4[time_ymdhis]' ";
sql_query($sql);
}
?>
추가,
view_comment.skin.php 코맨트리스트 코맨트내용 밑에
<? $aaa = get_file($bo_table, $comment_id); echo $aaa[0][view];?>
추가.
나올겁니다.
대충 만든거니 살은 직접 붙이세요.
basic 스킨기준입니다.
view_comment.skin.php 의 comment form 에 enctype="multipart/form-data" 추가,
적당한 위치에 <input type=file name=comment_file> 추가,
write_comment_update.skin.php 에
<?
if(is_uploaded_file($comment_file)) {
$tmp_file = $_FILES[comment_file][tmp_name];
$filename = $_FILES[comment_file][name];
$filesize = $_FILES[comment_file][size];
$dest = "$g4[path]/data/file/$bo_table/".$HTTP_POST_FILES[comment_file][name];
move_uploaded_file($HTTP_POST_FILES[comment_file][tmp_name], "$dest");
$imagesize = @getimagesize($dest);
$sql = " insert into $g4[board_file_table]
set bo_table = '$bo_table',
wr_id = '$comment_id',
bf_no = '0',
bf_source = '$filename',
bf_file = '$filename',
bf_content = '{$bf_content}',
bf_download = 0,
bf_filesize = '$filesize',
bf_width = '{$imagesize[0]}',
bf_height = '{$imagesize[1]}',
bf_type = '{$imagesize[2]}',
bf_datetime = '$g4[time_ymdhis]' ";
sql_query($sql);
}
?>
추가,
view_comment.skin.php 코맨트리스트 코맨트내용 밑에
<? $aaa = get_file($bo_table, $comment_id); echo $aaa[0][view];?>
추가.
나올겁니다.
아....감사합니다...
당장 실행해보고 바로 보고 올리겠습니다.^^
당장 실행해보고 바로 보고 올리겠습니다.^^
굿입니다...나옵니다...^^
행복한 주말 되세요~~
감사합니다.
행복한 주말 되세요~~
감사합니다.
두분 답변 감사합니다...^^
뮤존님것도 유용할것같은데...김영삼님의 말씀 처럼 코멘트도 id를 부여 하는군요..ㅜ.ㅜ
효율적인걸 먼저 시행해보겠습니다.
뮤존님것도 유용할것같은데...김영삼님의 말씀 처럼 코멘트도 id를 부여 하는군요..ㅜ.ㅜ
효율적인걸 먼저 시행해보겠습니다.
파일처리
어유 고맙습니다... 이 문제로 고심했는데 덕분에 잘 해결 했습니다..^^
좋은팁 스크랩합니다~!
코멘트 첨부파일