반응형
<input file/>로 받은 후,
<?php
include_once($_SERVER[DOCUMENT_ROOT].'/common/Prog/images.lib.php');
$usr_logo = $_FILES['usr_logo'];
$file_ext1 = explode(".", strrev($usr_logo["name"]));
$file_ext1 = strrev($file_ext1[0]);
$img_ok = array("gif", "png", "peg", "jpg", "jpeg", "bmp", "GIF", "PNG", "JPG", "JPEG", "BMP");
/************ 이미지파일 체크 *************/
if($usr_logo["tmp_name"] != ""){
if(!in_array($file_ext1, $img_ok)){
echo "로고이미지는 이미지파일만 업로드가능합니다.";
exit;
}
}
/************ 이미지사이즈 체크 *************/
$imgSize = getimagesize($usr_logo['tmp_name']);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
if($imgWidth != 200 || $imgHeight != 45){
echo "로고이미지는 200x45사이즈만 가능합니다.";
exit;
}
//db add query text
$sql_imgfiles = '';
//로고이미지가 있으면
if(file_exists($usr_logo['tmp_name']) && is_uploaded_file($usr_logo['tmp_name'])) {
$upfile_path = $_SERVER[DOCUMENT_ROOT]."/img/upfile/";
$thumbS_width = 400;
$thumbS_height = 300;
$tmp_file = $usr_logo[tmp_name];
$filename = $usr_logo[name];
if(!is_dir($upfile_path)){ // 업로드 디렉토리 생성
echo exec("mkdir $upfile_path");
exec("chmod 707 $upfile_path");
}
if(is_uploaded_file($tmp_file)) {
//랜덤 파일명생성
//str_replace('%', '', urlencode($filename));
$filepath = date('Ymd') .'_'. abs(ip2long($_SERVER[REMOTE_ADDR])) .'_'. substr(md5(uniqid($server_time)), 0, 8).".".$file_ext1;
$dest_file = $upfile_path. $filepath;
$error_code = move_uploaded_file($tmp_file, $dest_file) or die($usr_logo[error][$i]);
chmod($dest_file, 0606);
$upload[$i][image] = @getimagesize($dest_file);
if(img_type($dest_file)) {
$srcimg = $filepath;
$dstimg = "l_". $filepath;
//썸네일 저장
makeThumb($upfile_path, $filepath, $thumbS_width, $thumbS_height, $upfile_path, $dstimg, 'ratio');
$sql_imgfiles .= " , usr_lOGO = '{$dstimg}' ";
}
}else{
echo "<이미지 업로드에 실패했습니다.";
exit;
}
}
?>
반응형
'프로그래밍 > PHP' 카테고리의 다른 글
| php mysql 트랜잭션 사용 (0) | 2017.07.11 |
|---|---|
| php form enctype="multipart/form-data" 사용시 request 한글깨짐 (0) | 2017.07.11 |
| php mysql db select json print (0) | 2017.07.10 |
| php mb_substr() 문자열 ...처리하기 (0) | 2017.07.10 |
| php explode() 문자열 나누기/분리하기 (0) | 2017.07.10 |
images.lib.zip