if ($mw_basic[cf_comment_file]) { $upload = array(); $chars_array = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z')); // 삭제에 체크가 되어있다면 파일을 삭제합니다. if ($_POST[bf_file_del]) { $upload[del_check] = true; $row = sql_fetch(" select bf_file from {$mw['comment_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$comment_id}' and bf_no = '0' "); @unlink("{$g4['path']}/data/file/{$bo_table}/{$row['bf_file']}"); } else { $upload[del_check] = false; } $tmp_file = $_FILES[bf_file][tmp_name]; $filesize = $_FILES[bf_file][size]; $filename = $_FILES[bf_file][name]; $filename = preg_replace('/(\\s|\\<|\\>|\\=|\\(|\\))/', '_', $filename); $filename = get_safe_filename($filename); // 서버에 설정된 값보다 큰파일을 업로드 한다면 if ($filename) { if ($_FILES[bf_file][error] == 1) { alert("\\'{$filename}\\' 파일의 용량이 서버에 설정({$upload_max_filesize})된 값보다 크므로 업로드 할 수 없습니다.\\n"); } else { if ($_FILES[bf_file][error] != 0) { alert("\\'{$filename}\\' 파일이 정상적으로 업로드 되지 않았습니다.\\n"); } } } if (is_uploaded_file($tmp_file)) { // 관리자가 아니면서 설정한 업로드 사이즈보다 크다면 건너뜀 if (!$is_admin && $filesize > $board[bo_upload_size]) { alert("\\'{$filename}\\' 파일의 용량(" . number_format($filesize) . " 바이트)이 게시판에 설정(" . number_format($board[bo_upload_size]) . " 바이트)된 값보다 크므로 업로드 하지 않습니다.\\n"); //continue;
make_dir($path); $obj = $_POST[obj]; $token = $_POST[token]; $work = $_POST[work]; if (!$token) { exit; } if (!$obj) { alert_only('오브젝트 변수가 없습니다.'); } if ($work == 'delete') { delete_image($token, $path . '/' . date('ym')); exit; } $file = $_FILES[image]; $file[name] = get_safe_filename($file[name]); $size = getImageSize($file[tmp_name]); $mime = array('image/png', 'image/jpeg', 'image/gif'); if (!is_uploaded_file($file[tmp_name])) { alert_only("첨부파일이 업로드되지 않았습니다.\\n\\n{$file['error']}"); } if ($file[size] > $byte) { alert_only("{$byte} byte 까지 업로드 가능합니다."); } if (!in_array($size['mime'], $mime)) { alert_only("PNG, GIF, JPG 형식의 이미지 파일만 업로드 가능합니다."); } if (!preg_match("/\\.(jpg|png|gif)\$/i", $file[name])) { alert_only("PNG, GIF, JPG 형식의 이미지 파일만 업로드 가능합니다."); } if (!is_dir($path)) {
alert_close("자신의 사진만 변경 가능합니다."); } if (!mb_id_check($mb_id)) { alert_close("존재하지 않는 회원입니다."); } $path = $comment_image_path; $dest_file = $path . '/' . $mb_id; @mkdir($path, 0707); @chmod($path, 0707); $indexfile = $path . "/index.php"; $f = @fopen($indexfile, "w"); @fwrite($f, ""); @fclose($f); @chmod($indexfile, 0606); $file = $_FILES['comment_image']; $file['name'] = get_safe_filename($file['name']); $size = @getImageSize($file['tmp_name']); $mime = array('image/png', 'image/jpeg', 'image/gif'); $exts = array('png', 'jpg', 'gif'); if ($size[0] > $cf_x) { alert("가로사이즈가 {$cf_x}px 보다 큽니다."); } if ($size[1] > $cf_y) { alert("세로사이즈가 {$cf_y}px 보다 큽니다."); } if ($file['size'] > $cf_size) { alert("파일용량이 " . get_filesize($cf_size) . " 보다 큽니다."); } $ext = substr($file['name'], strlen($file['name']) - 3, 3); if ($image_del) { @unlink($dest_file);
function apms_upload_file($dir, $pf_id) { global $config, $g5, $default; if (!$pf_id) { return; } //파일타입 설정 switch ($dir) { case 'item': $pf_dir = 1; $pf_file = G5_DATA_PATH . '/item/' . $pf_id; break; case 'partner': $pf_dir = 2; $pf_file = G5_DATA_PATH . '/apms/' . $dir; break; default: return; } //디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.) @mkdir($pf_file, G5_DIR_PERMISSION); @chmod($pf_file, 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['pf_file']['name']); $i++) { $upload[$i]['id'] = $pf_id; $upload[$i]['dir'] = $pf_dir; $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]['guest_use'] = isset($_POST['pf_guest'][$i]) && $_POST['pf_guest'][$i] ? 1 : 0; $upload[$i]['purchase_use'] = isset($_POST['pf_purchase'][$i]) && $_POST['pf_purchase'][$i] ? 1 : 0; $upload[$i]['download_use'] = isset($_POST['pf_download'][$i]) && $_POST['pf_download'][$i] ? 1 : 0; $upload[$i]['view_use'] = isset($_POST['pf_view'][$i]) && $_POST['pf_view'][$i] ? 1 : 0; // 삭제에 체크가 되어있다면 파일을 삭제합니다. if (isset($_POST['pf_file_del'][$i]) && $_POST['pf_file_del'][$i]) { $upload[$i]['del_check'] = true; $row = sql_fetch(" select pf_file from {$g5['apms_file']} where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "); @unlink($pf_file . '/' . $row['pf_file']); } else { $upload[$i]['del_check'] = false; } $tmp_file = $_FILES['pf_file']['tmp_name'][$i]; $filesize = $_FILES['pf_file']['size'][$i]; $filename = $_FILES['pf_file']['name'][$i]; $filename = get_safe_filename($filename); // 서버에 설정된 값보다 큰파일을 업로드 한다면 if ($filename) { if ($_FILES['pf_file']['error'][$i] == 1) { $file_upload_msg .= '\\"' . $filename . '\\" 파일의 용량이 서버에 설정(' . ini_get('upload_max_filesize') . ')된 값보다 크므로 업로드 할 수 없습니다.\\n'; continue; } else { if ($_FILES['pf_file']['error'][$i] != 0) { $file_upload_msg .= '\\"' . $filename . '\\" 파일이 정상적으로 업로드 되지 않았습니다.\\n'; continue; } } } if (is_uploaded_file($tmp_file)) { // 관리자가 아니면서 설정한 업로드 사이즈보다 크다면 건너뜀 if (!$is_admin && $filesize > $default['pt_upload_size']) { $file_upload_msg .= '\\"' . $filename . '\\" 파일의 용량(' . number_format($filesize) . ' 바이트)이 설정(' . number_format($default['pt_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; // 프로그램 원래 파일명 $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 = $pf_file . '/' . $upload[$i]['file']; // 업로드가 안된다면 에러메세지 출력하고 죽어버립니다. $error_code = move_uploaded_file($tmp_file, $dest_file) or die($_FILES['pf_file']['error'][$i]); // 올라간 파일의 퍼미션을 변경합니다. chmod($dest_file, G5_FILE_PERMISSION); } } //------------------------------------------------------------------------------ // 가변 파일 업로드 for ($i = 0; $i < count($upload); $i++) { //파일유형체크 $upload[$i]['ext'] = apms_check_ext($upload[$i]['source']); if (!get_magic_quotes_gpc()) { $upload[$i]['source'] = addslashes($upload[$i]['source']); } $row = sql_fetch(" select count(*) as cnt from {$g5['apms_file']} where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "); if ($row['cnt']) { // 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다. // 그렇지 않다면 내용만 업데이트 합니다. if ($upload[$i]['del_check'] || $upload[$i]['file']) { $sql = " update {$g5['apms_file']}\n\t\t\t\t\t\t\tset pf_source\t\t= '{$upload[$i]['source']}',\n\t\t\t\t\t\t\t\tpf_file\t\t\t= '{$upload[$i]['file']}',\n\t\t\t\t\t\t\t\tpf_filesize\t\t= '{$upload[$i]['filesize']}',\n\t\t\t\t\t\t\t\tpf_width\t\t= '{$upload[$i]['image']['0']}',\n\t\t\t\t\t\t\t\tpf_height\t\t= '{$upload[$i]['image']['1']}',\n\t\t\t\t\t\t\t\tpf_type\t\t\t= '{$upload[$i]['image']['2']}',\n\t\t\t\t\t\t\t\tpf_guest_use\t= '{$upload[$i]['guest_use']}',\n\t\t\t\t\t\t\t\tpf_purchase_use = '{$upload[$i]['purchase_use']}',\n\t\t\t\t\t\t\t\tpf_download_use = '{$upload[$i]['download_use']}',\n\t\t\t\t\t\t\t\tpf_view_use\t\t= '{$upload[$i]['view_use']}',\n\t\t\t\t\t\t\t\tpf_ext\t\t\t= '{$upload[$i]['ext']}',\n\t\t\t\t\t\t\t\tpf_datetime\t\t= '" . G5_TIME_YMDHIS . "'\n\t\t\t\t\t\t where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "; sql_query($sql); } else { $sql = " update {$g5['apms_file']}\n\t\t\t\t\t\t\tset\tpf_guest_use\t= '{$upload[$i]['guest_use']}',\n\t\t\t\t\t\t\t\tpf_purchase_use = '{$upload[$i]['purchase_use']}',\n\t\t\t\t\t\t\t\tpf_download_use = '{$upload[$i]['download_use']}',\n\t\t\t\t\t\t\t\tpf_view_use\t\t= '{$upload[$i]['view_use']}'\n\t\t\t\t\t\t where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "; sql_query($sql); } } else { $sql = " insert into {$g5['apms_file']}\n\t\t\t\t\t\tset pf_id\t\t\t\t= '{$upload[$i]['id']}',\n\t\t\t\t\t\t\tpf_no\t\t\t\t= '{$i}',\n\t\t\t\t\t\t\tpf_source\t\t\t= '{$upload[$i]['source']}',\n\t\t\t\t\t\t\tpf_file\t\t\t\t= '{$upload[$i]['file']}',\n\t\t\t\t\t\t\tpf_download\t\t\t= '0',\n\t\t\t\t\t\t\tpf_filesize\t\t\t= '{$upload[$i]['filesize']}',\n\t\t\t\t\t\t\tpf_width\t\t\t= '{$upload[$i]['image']['0']}',\n\t\t\t\t\t\t\tpf_height\t\t\t= '{$upload[$i]['image']['1']}',\n\t\t\t\t\t\t\tpf_type\t\t\t\t= '{$upload[$i]['image']['2']}',\n\t\t\t\t\t\t\tpf_guest_use\t\t= '{$upload[$i]['guest_use']}',\n\t\t\t\t\t\t\tpf_purchase_use\t\t= '{$upload[$i]['purchase_use']}',\n\t\t\t\t\t\t\tpf_download_use\t\t= '{$upload[$i]['download_use']}',\n\t\t\t\t\t\t\tpf_view_use\t\t\t= '{$upload[$i]['view_use']}',\n\t\t\t\t\t\t\tpf_dir\t\t\t\t= '{$upload[$i]['dir']}',\n\t\t\t\t\t\t\tpf_ext\t\t\t\t= '{$upload[$i]['ext']}',\n\t\t\t\t\t\t\tpf_datetime\t\t\t= '" . G5_TIME_YMDHIS . "' "; sql_query($sql); } } // 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서 // 파일 정보가 없다면 테이블의 내용을 삭제합니다. $row = sql_fetch(" select max(pf_no) as max_pf_no from {$g5['apms_file']} where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' "); for ($i = (int) $row['max_pf_no']; $i >= 0; $i--) { $row2 = sql_fetch(" select pf_file from {$g5['apms_file']} where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "); // 정보가 있다면 빠집니다. if ($row2['pf_file']) { break; } // 그렇지 않다면 정보를 삭제합니다. sql_query(" delete from {$g5['apms_file']} where pf_id = '{$pf_id}' and pf_dir = '{$pf_dir}' and pf_no = '{$i}' "); } return $file_upload_msg; }