첨부파일 불러오기 채택완료
adm에 member_form에 업로드를 할수 있는 곳을 5군대 만들어놨습니다~.
$file_count = 5;
for ($i=0; $is_file || $i<$file_count; $i++) {
$mb_dir3 = substr($mb['mb_id'],0,2);
?>
$mb_dir2 = substr($mb_id,0,2);
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
@mkdir(G5_DATA_PATH.'/member/'.$mb_dir2, G5_DIR_PERMISSION);
@chmod(G5_DATA_PATH.'/member/'.$mb_dir2, 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 $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] = ''; // 삭제에 체크가 되어있다면 파일을 삭제합니다. if (isset($_POST['bf_file_del'][$i]) && $_POST['bf_file_del'][$i]) { $upload[$i]['del_check'] = true; $row = sql_fetch(" select bf_file from g5_seller_file where mb_id = '{$mb_id}' and wr_id = '{$wr_id}' and bf_no = '{$i}' "); @unlink(G5_DATA_PATH.'/member/'.$mb_dir2.'/'.$row['bf_file']); // 썸네일삭제 if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) { delete_board_thumbnail($mb_dir2, $row['bf_file']); // 여기 check } } 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'] > 16) continue; } //================================================================= $upload[$i]['image'] = $timg; // 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정 if ($w == 'u') { // 존재하는 파일이 있다면 삭제합니다. $row = sql_fetch(" select bf_file from g5_seller_file where mb_id = '$mb_id' and wr_id = '$wr_id' and bf_no = '$i' "); @unlink(G5_DATA_PATH.'/member/'.$mb_dir2.'/'.$row['bf_file']); // 이미지파일이면 썸네일삭제 if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) { delete_board_thumbnail($mb_dir2, $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); 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.'/member/'.$mb_dir2.'/'.$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); } } for ($i=0; $i { if (!get_magic_quotes_gpc()) { $upload[$i]['source'] = addslashes($upload[$i]['source']); } $row = sql_fetch(" select count(*) as cnt from g5_seller_file where mb_id = '{$mb_id}' and wr_id = '{$wr_id}' and bf_no = '{$i}' "); if ($row['cnt']) { // 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다. // 그렇지 않다면 내용만 업데이트 합니다. if ($upload[$i]['del_check'] || $upload[$i]['file']) { $sql = " update g5_seller_file 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 = '".G5_TIME_YMDHIS."' where mb_id = '{$mb_id}' and wr_id = '{$wr_id}' and bf_no = '{$i}' "; sql_query($sql); } else { $sql = " update g5_seller_file set bf_content = '{$bf_content[$i]}' where mb_id = '{$mb_id}' and wr_id = '{$wr_id}' and bf_no = '{$i}' "; sql_query($sql); } } else { $sql = " insert into g5_seller_file set mb_id = '{$mb_id}', 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 = '".G5_TIME_YMDHIS."' "; sql_query($sql); } } 
답변 3개
function image_view($mb_id, $wr_id, $bf_no, $width, $height)
{
$sql = " select * from g5_seller_file where mb_id= '$mb_id' and wr_id = '$wr_id' and bf_no = '$bf_no'";
$result = sql_query($sql);
$row=sql_fetch_array($result);
$str .= "";
return $str;
}
common.lib.php 에 넣으시구
호출하고자 하는 페이지에서 함수 호출하여 사용해보세요.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
echo image_view("$mb_id", "$wr_id", "$bf_file", "$width", "$height");
echo image_view("$mb_id", "$wr_id", "$bf_no", "$width", "$height"); 였네요.ㅠㅠ
업로드된 파일이 5개로 고정되었을시...
echo image_view("$mb_id", "$wr_id", "$i", "$width", "$height");
}?>
업로드된 파일이 유동적일때는 조건식을 변경해주시면 될거 같습니다.
답변에 대한 댓글 1개
감사합니다 ㅎㅎㅎ
댓글을 작성하려면 로그인이 필요합니다.
칼럼명 : bf_source는 업로드한 본래 이미지 명이며,
칼럼명 : bf_file 은 파일업로드 시 중복된 파일명이 있을시, 파일이 덮어 써지는것을 막기위해 token?값을 넣은 것으로 알고 있습니다. 본래 이름을 호출하고자 하시면 $row['bf_source']를 하시면 되나~ 이미지는 불러올수 없습니다.
답변에 대한 댓글 1개
그런데 ...
<?
$file_count = 5;
for ($i=0; $is_file || $i<$file_count; $i++) {
$mb_dir3 = substr($mb['mb_id'],0,2);
?>
<tr>
<th scope="row">파일 #<?php echo $i+1 ?></th>
<td>
<input type="file" name="bf_file[]" title="파일첨부 <?php echo $i+1 ?> : 용량 <?php echo $upload_max_filesize ?> 이하만 업로드 가능" class="frm_file frm_input">
<?php if ($is_file_content) { ?>
<input type="text" name="bf_content[]" value="<?php echo ($w == 'u') ? $file[$i]['bf_content'] : ''; ?>" title="파일 설명을 입력해주세요." class="frm_file frm_input" size="50">
<?php } ?>
<?php if($w == 'u' && $file[$i]['file']) { ?>
<input type="checkbox" id="bf_file_del<?php echo $i ?>" name="bf_file_del[<?php echo $i; ?>]" value="1"> <label for="bf_file_del<?php echo $i ?>"><?php echo $row[$i]['bf_file'].'('.$file[$i]['size'].')'; ?> 파일 삭제</label>
<?php } ?>
</td><?php echo $str[$i]['bf_file']; ?>
</tr>
<?php } ?>
이런식으로 파일을 불러 올때 ( 파일이 5개 )
어떻게 해야되나요?
<?php echo image_view("$mb_id", "$wr_id", "$bf_file", "$width", "$height");?>
요렇게 하면
똑같은 이미지만 5개가 나와서요 ..ㅎㅎ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
그런데
$str .= $row[bf_file];
이렇게 하니깐 암호화된 파일이름이 나던데
원래 이름은.... 어떻게 호출하시는지 아시나요?ㅎ