회원사진 / 게시판 파일첨부 처럼 올리고 삭제하기/관리자모드에서도 똑같이 활용하기 정보
회원사진 / 게시판 파일첨부 처럼 올리고 삭제하기/관리자모드에서도 똑같이 활용하기본문
프로그래머가 아닌 생초보이기에 말도 안되는 짜집기 말 그대로 그냥 짜집기했습니다.
질문과답변 게시판에 문의했는데 답변이 없기에 왜 내꺼는 안해주나?;; 했는데..제가 직접해보니
그럴만도 하겠구나라는 생각이 들었습니다.
지금은 기분이 좋습니다. 어떻게 되었는 직접 해결을 했으니까요. ^^
그래서 저 처럼 초보자들의 애환을 조금이라도 달래고 동변상련의 아픔속에서 조금이나 벗어나시길 바라며 만들자 마자 따근한 소스를 올립니다.
참고로 제가 짜집기 했지만 왜 이렇게 돌아가는지는 모릅니다 ㅠㅠ;;
다만 강사구인 구직 홈페이지를 만들면서 꼭 필요하기에 만들었습니다.
파일 첨부하면 오른쪽에 첨부된 이미지가 나타납니다.
(불당썸을 설치를 하셔야 합니다. !! 저는 불당님 팬입니다 ^^)
그리고 가급적 저한테는 질문은 피해주시기 바랍니다.
서두에 말씀드린것 처럼 생초보입니다.ㅠㅠ;
그냥 오류 없이 잘 돌아간다는 느낌이 듭니다.
상세한 질문은 다른 고수분들께 여쭤 보시기 바랍니다.
일단 휘향 찬란한 스크롤이 예상 되는군요.
1. config.php 10줄에 추가
$g4['bbs_img_path'] = $g4['path'] . "/" . $g4['bbs'] . "/" . $g4['bbs_img'];
___________________________________________________________________________________
2. lib/common.lib.php 241줄(게시판에 첨부된 파일을 얻는다 내용 뒤에)
//*****************************************************************start
function get_file_img($mb_id)
{
global $g4, $qstr;
$file["count"] = 0;
$sql = " select * from $g4[member_img_table] where mb_id order by bf_no ";
$result = sql_query($sql);
while ($row = sql_fetch_array($result))
{
$no = $row[bf_no];
$file[$no][href] = "./download_img.php?mb_id=$mb_id&no=$no" . $qstr;
$file[$no][download] = $row[bf_download];
// 4.00.11 - 파일 path 추가
$file[$no][path] = "$g4[path]/data/member_img/$mb_id";
//$file[$no][size] = get_filesize("{$file[$no][path]}/$row[bf_file]");
$file[$no][size] = get_filesize($row[bf_filesize]);
//$file[$no][datetime] = date("Y-m-d H:i:s", @filemtime("$g4[path]/data/file/$bo_table/$row[bf_file]"));
$file[$no][datetime] = $row[bf_datetime];
$file[$no][source] = $row[bf_source];
$file[$no][bf_content] = $row[bf_content];
$file[$no][content] = get_text($row[bf_content]);
//$file[$no][view] = view_file_link($row[bf_file], $file[$no][content]);
$file[$no][view] = view_file_link($row[bf_file], $row[bf_width], $row[bf_height], $file[$no][content]);
$file[$no][file] = $row[bf_file];
// prosper 님 제안
//$file[$no][imgsize] = @getimagesize("{$file[$no][path]}/$row[bf_file]");
$file[$no][image_width] = $row[bf_width] ? $row[bf_width] : 640;
$file[$no][image_height] = $row[bf_height] ? $row[bf_height] : 480;
$file[$no][image_type] = $row[bf_type];
$file["count"]++;
}
return $file;
}
//***************************************************************** End
3. skin/member/default 사진추가 등록하고 싶은곳에...
<!-- ////////////////////////////////// 사진 추가 S ///////////////////////////// -->
<tr>
<td class=write_head>
<table cellpadding=0 cellspacing=0>
<tr>
<td class=write_head style="padding-top:10px; line-height:20px;">활동사진<br>
<span onclick="add_file();" style="cursor:pointer;"><img src="<?=$member_skin_path?>/img/btn_file_add.gif"></span>
<span onclick="del_file();" style="cursor:pointer;"><img src="<?=$member_skin_path?>/img/btn_file_minus.gif"></span>
</td>
</tr>
</table>
</td>
<td class=m_padding><table id="variableFiles" cellpadding=0 cellspacing=0></table><?// print_r2($file); ?>
<script language="Javascript">
var flen = 0;
function add_file(delete_code)
{
var upload_count = <?=(int)$config[cf_member_img_upload_count]?>;
if (upload_count && flen >= upload_count)
{
alert("회원 사진 업로드는 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
return;
}
var objTbl;
var objRow;
var objCell;
if (document.getElementById)
objTbl = document.getElementById("variableFiles");
else
objTbl = document.all["variableFiles"];
objRow = objTbl.insertRow(objTbl.rows.length);
objCell = objRow.insertCell(0);
objCell.innerHTML = "<br><input type='file' class='ed' style='width:250px;' name='bf_file[]' title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능'>";
if (delete_code)
objCell.innerHTML += delete_code;
else
{
<? if ($is_file_content) { ?>
objCell.innerHTML += "<br><input type='text' class='ed' size=50 name='bf_content[]' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
<? } ?>
;
}
flen++;
}
<?=$file_script; //수정시에 필요한 스크립트?>
function del_file()
{
// file_length 이하로는 필드가 삭제되지 않아야 합니다.
var file_length = <?=(int)$file_length?>;
var objTbl = document.getElementById("variableFiles");
if (objTbl.rows.length - 1 > file_length)
{
objTbl.deleteRow(objTbl.rows.length - 1);
flen--;
}
}
</script> (총 <?=$config[cf_member_img_upload_count]?> 개의 파일 업로드 가능) <br> 파일 제한용량은 <span style="color:#000;"><?=$config[cf_member_img_upload_size]?></span> 입니다. 올릴수있는갯수 <span style="color:#000;"><?=$config[cf_member_img_upload_count]?></span>개
</td>
</tr>
<tr><td height=1 colspan=2 bgcolor=#eeeeee></td></tr>
--------------------------------------------------------------------------------------
4. /bbs/register_form.php 회원가입관련 끝 84줄 (회원 아이콘 경로 바로위에)
//************************************************************************************
$file = get_file_img($mb_id);
// 가변 파일
$file_script = "";
$file_length = -1;
// 수정의 경우 파일업로드 필드가 가변적으로 늘어나야 하고 삭제 표시도 해주어야 합니다.
if ($w == "u")
{
for ($i=0; $i<$file[count]; $i++)
{
$row = sql_fetch(" select bf_file, bf_content from $g4[member_img_table] where mb_id='$mb_id' and bf_no = '$i' ");
if ($row[bf_file])
{
////////////////////////////////////////////////////////////////////////////////
$data_path = $g4['path'] . "/data/member_img/$mb_id/";// 원본 경로
//파일 뽑기
$sql_1 = " select bf_file from $g4[member_img_table] where mb_id = '$mb_id' order by bf_no= '$i' ";
$result_1 = sql_query($sql_1);
for ($j=0; $row_1 = sql_fetch_array($result_1); $j++) {
$view_one = "$data_path/{$row_1[bf_file]}"; // 원본 파일 경로
$thumb_img=thumbnail($view_one, 60, 40, 0, 1, 90); // 썸네일 출력
}
//////////////////////////////////////////////////////////////////////////////
//$file_script .= "add_file(\"<input type='checkbox' name='bf_file_del[$i]' value='1'><a href='{$file[$i][href]}'><img src='$view_one'>{$file[$i][source]}({$file[$i][size]})</a> 파일 삭제";
$file_script .= "add_file(\"<input type='checkbox' name='bf_file_del[$i]' value='1'><img src='$thumb_img' align='absmiddle' style='border:1px solid #cccccc;'> {$file[$i][source]}({$file[$i][size]}) [파일삭제]";
if ($is_file_content)
//$file_script .= "<br><input type='text' class=ed size=50 name='bf_content[$i]' value='{$row[bf_content]}' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
// 첨부파일설명에서 ' 또는 " 입력되면 오류나는 부분 수정
$file_script .= "<br><input type='text' class=ed size=50 name='bf_content[$i]' value='".addslashes(get_text($row[bf_content]))."' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
$file_script .= "\");\n";
}
else
$file_script .= "add_file('');\n";
}
$file_length = $file[count] - 1;
}
if ($file_length < 0)
{
$file_script .= "add_file('');\n";
$file_length = 0;
}
//************************************************************************************
--------------------------------------------------------------------------------------
5. /bbs/register_form_update.php
23줄 정도 // 리퍼러 체크 바로 위
//******************************************************************************
$upload_max_filesize = ini_get('upload_max_filesize');
if (empty($_POST))
alert("파일 또는 글내용의 크기가 서버에서 설정한 값을 넘어 오류가 발생하였습니다.\\n\\npost_max_size=".ini_get('post_max_size')." , upload_max_filesize=$upload_max_filesize\\n\\n관리자에게 문의 바랍니다.");
//******************************************************************************
122줄 정도 //아이콘 삭제 위
//************************************** Start
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
@mkdir("$g4[path]/data/member_img/$mb_id", 0707);
@chmod("$g4[path]/data/merber_img/$mb_id", 0707);
// "인터넷옵션 > 보안 > 사용자정의수준 > 스크립팅 > Action 스크립팅 > 사용 안 함" 일 경우의 오류 처리
// 이 옵션을 사용 안 함으로 설정할 경우 어떤 스크립트도 실행 되지 않습니다.
//if (!$_POST[wr_content]) die ("내용을 입력하여 주십시오.");
$chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));
//print_r2($chars_array); exit;
// 가변 파일 업로드
$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[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/member_img/$mb_id/$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 > $config[cf_member_img_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] > 16)
{
//$file_upload_msg .= "\'{$filename}\' 파일이 이미지나 플래시 파일이 아닙니다.\\n";
continue;
}
}
//=================================================================
$upload[$i][image] = $timg;
// 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정
if ($w == 'u')
{
// 존재하는 파일이 있다면 삭제합니다.
$row = sql_fetch(" select bf_file from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/member_img/$mb_id/$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));
shuffle($chars_array);
$shuffle = implode("", $chars_array);
// 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
//$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode($filename));
$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode(str_replace(' ', '_', $filename)));
$dest_file = "$g4[path]/data/member_img/$mb_id/" . $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);
}
}
//**************************************************** / End /
약 478 사용자 실행코드 바로 위
//*********************************************************************************************
// 가변 파일 업로드
// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
for ($i=0; $i<count($upload); $i++)
{
$row = sql_fetch(" select count(*) as cnt from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
if ($row[cnt])
{
// 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다.
// 그렇지 않다면 내용만 업데이트 합니다.
if ($upload[$i][del_check] || $upload[$i][file])
{
$sql = " update $g4[member_img_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 mb_id = '$mb_id'
and bf_no = '$i' ";
sql_query($sql);
}
else
{
$sql = " update $g4[member_img_table]
set bf_content = '{$bf_content[$i]}'
where mb_id = '$mb_id'
and bf_no = '$i' ";
sql_query($sql);
}
}
else
{
$sql = " insert into $g4[member_img_table]
set mb_id = '$mb_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[member_img_table] where mb_id = '$mb_id' ");
for ($i=(int)$row[max_bf_no]; $i>=0; $i--)
{
$row2 = sql_fetch(" select bf_file from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
// 정보가 있다면 빠집니다.
if ($row2[bf_file]) break;
// 그렇지 않다면 정보를 삭제합니다.
sql_query(" delete from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
}
//*********************************************************************************************
맨 아래에 추가
//**********************************************************************************************
if ($file_upload_msg)
alert($file_upload_msg, "{$https_url}/register_form.php?mb_id=$mb_id" . $qstr);
else
goto_url("{$https_url}/register_form.php?mb_id=$mb_id" . $qstr);
//**********************************************************************************************
4. admin/config_form.php 약 307줄(어디든 상관없음 넣고 싶은곳에..참고로 회원가입약관 위에 배치했음
업로드 갯수와 파일용량
<!-- ******************************************************************************** -->
<tr><td colspan=4 class=line2></td></tr>
<tr class='ht'>
<td>회원추가사진 업로드 갯수</td>
<td colspan=3><input type=text class=ed name=cf_member_img_upload_count size=10 required itemname='회원사진 업로드 갯수' value='<?=$config[cf_member_img_upload_count]?>'> 게시물 한건당 업로드 할 수 있는 파일의 최대 개수 (0 이면 제한 없음)</td>
</tr>
<?
$upload_max_filesize = ini_get("upload_max_filesize");
if (!preg_match("/([m|M])$/", $upload_max_filesize)) {
$upload_max_filesize = (int)($upload_max_filesize / 1048576);
}
?>
<tr class='ht'>
<td>파일 업로드 용량</td>
<td colspan=3>업로드 파일 한개당 <input type=text class=ed name=cf_member_img_upload_size size=10 required itemname='추가사진 업로드 용량' value='<?=$config[cf_member_img_upload_size]?>'> bytes 이하 (최대 <?=ini_get("upload_max_filesize")?> 이하)<?=help("1 MB = 1,024,768 bytes")?></td>
</tr>
<tr><td colspan=4 class=line2></td></tr>
<!-- ******************************************************************************** -->
5. adm/config_form_update.php sql 문에 추가 약 85줄 cf_member_icon_size 밑에...
cf_member_img_upload_count = '$_POST[cf_member_img_upload_count]',
cf_member_img_upload_size = '$_POST[cf_member_img_upload_size]',
6. adm/member_form.php 약 250줄 정도(넣고 싶은곳에 임의로 넣어도 됩니다. 저는 참고로 여분필드 위에 넣었습니다.
<?
//*********************활동 사진 등록을 위한 register_form 소스 대입*********************************
$file = get_file_img($mb_id);
// 가변 파일
$file_script = "";
$file_length = -1;
// 수정의 경우 파일업로드 필드가 가변적으로 늘어나야 하고 삭제 표시도 해주어야 합니다.
if ($w == "u")
{
for ($i=0; $i<$file[count]; $i++)
{
$row = sql_fetch(" select bf_file, bf_content from $g4[member_img_table] where mb_id='$mb_id' and bf_no = '$i' ");
if ($row[bf_file])
{
////////////////////////////////////////////////////////////////////////////////
$data_path = $g4['path'] . "/data/member_img/$mb_id/";// 원본 경로
//파일 뽑기
$sql_1 = " select bf_file from $g4[member_img_table] where mb_id = '$mb_id' order by bf_no= '$i' ";
$result_1 = sql_query($sql_1);
for ($j=0; $row_1 = sql_fetch_array($result_1); $j++) {
$view_one = "$data_path/{$row_1[bf_file]}"; // 원본 파일 경로
$thumb_img=thumbnail($view_one, 60, 40, 0, 1, 90); // 썸네일 출력
}
//////////////////////////////////////////////////////////////////////////////
//$file_script .= "add_file(\"<input type='checkbox' name='bf_file_del[$i]' value='1'><a href='{$file[$i][href]}'><img src='$view_one'>{$file[$i][source]}({$file[$i][size]})</a> 파일 삭제";
$file_script .= "add_file(\"<input type='checkbox' name='bf_file_del[$i]' value='1'><img src='$thumb_img' align='absmiddle' style='border:1px solid #cccccc;'> {$file[$i][source]}({$file[$i][size]}) [파일삭제]";
if ($is_file_content)
//$file_script .= "<br><input type='text' class=ed size=50 name='bf_content[$i]' value='{$row[bf_content]}' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
// 첨부파일설명에서 ' 또는 " 입력되면 오류나는 부분 수정
$file_script .= "<br><input type='text' class=ed size=50 name='bf_content[$i]' value='".addslashes(get_text($row[bf_content]))."' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
$file_script .= "\");\n";
}
else
$file_script .= "add_file('');\n";
}
$file_length = $file[count] - 1;
}
if ($file_length < 0)
{
$file_script .= "add_file('');\n";
$file_length = 0;
}
//************************************************************************************
?>
<tr class='ht'>
<td>활동사진등록<br>
<table cellpadding=0 cellspacing=0>
<tr>
<td class=write_head style="padding-top:10px; line-height:20px;">
<span onclick="add_file();" style="cursor:pointer;"><img src="<?=$g4[admin_path]?>/img/btn_file_add.gif"></span>
<span onclick="del_file();" style="cursor:pointer;"><img src="<?=$g4[admin_path]?>/img/btn_file_minus.gif"></span>
</td>
</tr>
</table>
</td>
<td colspan=3>
<table id="variableFiles" cellpadding=0 cellspacing=0></table><?// print_r2($file); ?>
<script language="Javascript">
var flen = 0;
function add_file(delete_code)
{
var upload_count = <?=(int)$config[cf_member_img_upload_count]?>;
if (upload_count && flen >= upload_count)
{
alert("회원 사진 업로드는 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
return;
}
var objTbl;
var objRow;
var objCell;
if (document.getElementById)
objTbl = document.getElementById("variableFiles");
else
objTbl = document.all["variableFiles"];
objRow = objTbl.insertRow(objTbl.rows.length);
objCell = objRow.insertCell(0);
objCell.innerHTML = "<br><input type='file' class='ed' style='width:250px;' name='bf_file[]' title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능'>";
if (delete_code)
objCell.innerHTML += delete_code;
else
{
<? if ($is_file_content) { ?>
objCell.innerHTML += "<br><input type='text' class='ed' size=50 name='bf_content[]' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
<? } ?>
;
}
flen++;
}
<?=$file_script; //수정시에 필요한 스크립트?>
function del_file()
{
// file_length 이하로는 필드가 삭제되지 않아야 합니다.
var file_length = <?=(int)$file_length?>;
var objTbl = document.getElementById("variableFiles");
if (objTbl.rows.length - 1 > file_length)
{
objTbl.deleteRow(objTbl.rows.length - 1);
flen--;
}
}
</script> (총 <?=$config[cf_member_img_upload_count]?> 개의 파일 업로드 가능) <br> 파일 제한용량은 <span style="color:#000;"><?=$config[cf_member_img_upload_size]?></span> 입니다. 올릴수있는갯수 <span style="color:#000;"><?=$config[cf_member_img_upload_count]?></span>개
</td>
</tr>
<tr><td colspan=4 class=line2></td></tr>
7. adm/member_form_update.php 약 100줄 정도에.. // if($mb_password) 바로 위에....
//************************************** Start **************************************************************************************회원활동사진
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
@mkdir("$g4[path]/data/member_img/$mb_id", 0707);
@chmod("$g4[path]/data/merber_img/$mb_id", 0707);
// "인터넷옵션 > 보안 > 사용자정의수준 > 스크립팅 > Action 스크립팅 > 사용 안 함" 일 경우의 오류 처리
// 이 옵션을 사용 안 함으로 설정할 경우 어떤 스크립트도 실행 되지 않습니다.
//if (!$_POST[wr_content]) die ("내용을 입력하여 주십시오.");
$chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));
//print_r2($chars_array); exit;
// 가변 파일 업로드
$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[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/member_img/$mb_id/$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 > $config[cf_member_img_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] > 16)
{
//$file_upload_msg .= "\'{$filename}\' 파일이 이미지나 플래시 파일이 아닙니다.\\n";
continue;
}
}
//=================================================================
$upload[$i][image] = $timg;
// 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정
if ($w == 'u')
{
// 존재하는 파일이 있다면 삭제합니다.
$row = sql_fetch(" select bf_file from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
@unlink("$g4[path]/data/member_img/$mb_id/$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));
shuffle($chars_array);
$shuffle = implode("", $chars_array);
// 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
//$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode($filename));
$upload[$i][file] = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode(str_replace(' ', '_', $filename)));
$dest_file = "$g4[path]/data/member_img/$mb_id/" . $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);
}
}
//**************************************************** / End / **************************************************************************
//*********************************************************************************************
// 가변 파일 업로드
// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
for ($i=0; $i<count($upload); $i++)
{
$row = sql_fetch(" select count(*) as cnt from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
if ($row[cnt])
{
// 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다.
// 그렇지 않다면 내용만 업데이트 합니다.
if ($upload[$i][del_check] || $upload[$i][file])
{
$sql = " update $g4[member_img_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 mb_id = '$mb_id'
and bf_no = '$i' ";
sql_query($sql);
}
else
{
$sql = " update $g4[member_img_table]
set bf_content = '{$bf_content[$i]}'
where mb_id = '$mb_id'
and bf_no = '$i' ";
sql_query($sql);
}
}
else
{
$sql = " insert into $g4[member_img_table]
set mb_id = '$mb_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[member_img_table] where mb_id = '$mb_id' ");
for ($i=(int)$row[max_bf_no]; $i>=0; $i--)
{
$row2 = sql_fetch(" select bf_file from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
// 정보가 있다면 빠집니다.
if ($row2[bf_file]) break;
// 그렇지 않다면 정보를 삭제합니다.
sql_query(" delete from $g4[member_img_table] where mb_id = '$mb_id' and bf_no = '$i' ");
}
//*********************************************************************************************end
8. /data/member_img
폴더 생성(아마 안해도 될듯합니다. 자동 생성 소스가 있긴합니다만..혹시 몰라서..
9. phpmyadmin 을 통한
가. g4_board_file 테이블을 g4_member_img 테이블로 하나 복사합니다.
나. 그리고 bo_table 필드명을 mb_id로 바뀌어 줍니다.
다. wr_id 필드를 삭제합니다.
끝~~~~~~
참고로 필요한 부분의 확인샷겸으로 이미지 몇장 올려드립니다.
6
댓글 7개

[윗 내용을 적용하면 에러납니다. 설명에서 빠진 부분을 알려드립니다.]
cf_member_img_upload_count = '$cf_member_img_upload_count',
cf_member_img_upload_size = '$cf_member_img_upload_size',
이렇게 추가하면 DB "g4_config" 에서 cf_member_img_upload_count 항목과 cf_member_img_upload_size를 추가해줘야 합니다.