php에서 업로드시 header 설정하기
업로드시와 페이지 정보 출력시 설정을 변경해줘야 해요
샘플소스)
hb_enter_proc.php 행사등록 처리페이지
업로드와 더불어 디비에 정보를 저장한 후에 메세지 출력 후 메인페이지로 이동하게 구현
<?
/*
역할 : 홍보정보 업로드 처리
비고 :
(***)업로드경로:/upload/book
MultiPartUpload : http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically
*/
session_start();
?>
<?
$lcTmplGvPathSet = "./..";
//MODULE : 파일
include_once($lcTmplGvPathSet."/resource/server/module/file.php");
include_once($lcTmplGvPathSet."/resource/server/module/Image.php");
//DOCUMENT ROOT를 가지고 간다.
$lcThisFileName=basename(__FILE__);
$lcTempFileName=realpath(__FILE__);
if(!$lcTempFileName)$lcTempFileName=__FILE__;
$lcOsDir=eregi_replace($lcThisFileName, "", $lcTempFileName);
unset($lcTempFileName);
$lcVirtualDir = eregi_replace($lcThisFileName, "", $PHP_SELF);
$lcOsDir = str_replace("\\", "/", $lcOsDir);
$lcDocumentRoot = str_replace($lcVirtualDir, "/", $lcOsDir);
CreateFolder($lcDocumentRoot, "/upload/book");//폴더가 생성안됐으면 생성
$flUploadDir = "book";
$flVar1 = 1;
$flVar2 = 1;
$flVar3 = 1;
$flVar4 = 1;
$flVar5 = 1;
$flVar6 = 1;
$flFileSize1 = 0;
$flFileSize2 = 0;
$flFileSize3 = 0;
$flFileSize4 = 0;
$flFileSize5 = 0;
$flFileSize6 = 0;
$flFileName1 = "";
$flFileName2 = "";
$flFileName3 = "";
$flFileName4 = "";
$flFileName5 = "";
$flFileName6 = "";
//1번째 파일을 업로드한다.
if($_FILES["img1"]["error"]>0){
$flFileSize1 = 0;
$flFileName1 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize1 = $_FILES["img1"]["size"];
$flFileName1 = $_FILES["img1"]["name"];
$flFileName1 = "B_".time()."1.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName1;
if(copy($_FILES["img1"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName1." has been uploaded";
}else{
$flFileSize1 = 0;
$flFileName1 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight=$imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징(550->1000)
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName1."<br>";
//echo "파일 사이즈:".$flFileSize1."<br>";
}
//2번째 파일을 업로드한다.
if($_FILES["img2"]["error"]>0){
$flFileSize2 = 0;
$flFileName2 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize2 = $_FILES["img2"]["size"];
$flFileName2 = $_FILES["img2"]["name"];
$flFileName2 = "B_".time()."2.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName2;
if(copy($_FILES["img2"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName2." has been uploaded";
}else{
$flFileSize2 = 0;
$flFileName2 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName2."<br>";
//echo "파일 사이즈:".$flFileSize2."<br>";
}
//3번째 파일을 업로드한다.
if($_FILES["img3"]["error"]>0){
$flFileSize3 = 0;
$flFileName3 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize3 = $_FILES["img3"]["size"];
$flFileName3 = $_FILES["img3"]["name"];
$flFileName3 = "B_".time()."3.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName3;
if(copy($_FILES["img3"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName3." has been uploaded";
}else{
$flFileSize3 = 0;
$flFileName3 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight=$imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징(550->1000)
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName3."<br>";
//echo "파일 사이즈:".$flFileSize3."<br>";
}
//4번째 파일을 업로드한다
if($_FILES["img4"]["error"]>0){
$flFileSize4 = 0;
$flFileName4 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize4 = $_FILES["img4"]["size"];
$flFileName4 = $_FILES["img4"]["name"];
$flFileName4 = "B_".time()."4.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName4;
if(copy($_FILES["img4"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName4." has been uploaded";
}else{
$flFileSize4 = 0;
$flFileName4 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징(550->1000)
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName4."<br>";
//echo "파일 사이즈:".$flFileSize4."<br>";
}
//5번째 파일을 업로드한다.
if($_FILES["img5"]["error"]>0){
$flFileSize5 = 0;
$flFileName5 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize5 = $_FILES["img5"]["size"];
$flFileName5 = $_FILES["img5"]["name"];
$flFileName5 = "B_".time()."5.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName5;
if(copy($_FILES["img5"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName5." has been uploaded";
}else{
$flFileSize5 = 0;
$flFileName5 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징(550->1000)
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName5."<br>";
//echo "파일 사이즈:".$flFileSize5."<br>";
}
//6번째 파일을 업로드한다.
if($_FILES["img6"]["error"]>0){
$flFileSize6 = 0;
$flFileName6 = "";
//echo "There was an error uploading the file, please try again!";
}else{
$flFileSize6 = $_FILES["img6"]["size"];
$flFileName6 = $_FILES["img6"]["name"];
$flFileName6 = "B_".time()."6.jpg";
$flUploadPath = $lcDocumentRoot."upload/".$flUploadDir."/".$flFileName6;
if(copy($_FILES["img6"]["tmp_name"], $flUploadPath)) {
//echo "The file ".$flFileName6." has been uploaded";
}else{
$flFileSize6 = 0;
$flFileName6 = "";
echo "There was an error uploading the file, please try again!";
}
//이미지 사이즈
$imgSize = getimagesize($flUploadPath);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
//이미지를 세워준다
if($imgWidth>$imgHeight){
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($flUploadPath);
$rotate = imagerotate($source, "-90", 0);
imagejpeg($rotate, $flUploadPath);
}
//이미지 리사이징(550->1000)
//if($imgWidth>1000){
$thumb = new Image($flUploadPath); //"image.jpg"
$thumb->width(1000);
$thumb->save();
//}
//echo "파일 네임:".$flFileName6."<br>";
//echo "파일 사이즈:".$flFileSize6."<br>";
}
header('Content-Type: text/html; charset=utf-8');
$lcTmplGvPathSet = "./..";
//전역변수
include_once($lcTmplGvPathSet."/config/variable/global_var.php");
include_once($lcTmplGvPathSet."/config/variable/global_var_mail.php");
//DATABASE START
include_once($lcTmplGvPathSet."/config/database/dbstart.php");
//MODULE : 이메일, 문자열, 날짜,페이징,파일,코드
include_once($lcTmplGvPathSet."/resource/server/module/mailClass.php");
include_once($lcTmplGvPathSet."/resource/server/module/string.php");
include_once($lcTmplGvPathSet."/resource/server/module/date.php");
include_once($lcTmplGvPathSet."/resource/server/module/paging.php");
include_once($lcTmplGvPathSet."/resource/server/module/code.php");
//파라미터
$parmLoginSeq = $login_seq; //유저번호
$parmCategory = $category; //카테고리
$parmHongboName = $hongbo_name; //홍보명
$parmSpaceSido = $space_sido; //장소(시도)
$parmSpaceAddinfo = $space_addinfo; //장소(추가장소정보)
$parmHp = $hp; //휴대폰번호
$parmAttendPrice = $attend_price; //참여가격
$parmHongboDesc = $hongbo_desc; //홍보설명
$parmCategory = fnStringChg($parmCategory, "'", "");
$parmHongboName = fnStringChg($parmHongboName, "'", "");
$parmHongboName = fnStringChg($parmHongboName, "\"", "");
$parmHongboName = fnStringChg($parmHongboName, "<", "");
$parmHongboName = fnStringChg($parmHongboName, ">", "");
$parmHongboDesc = fnStringChg($parmHongboDesc, "'", "");
$parmHongboDesc = fnStringChg($parmHongboDesc, "\"", "");
$parmHongboDesc = fnStringChg($parmHongboDesc, "<", "");
$parmHongboDesc = fnStringChg($parmHongboDesc, ">", "");
$parmSpaceAddinfo = fnStringChg($parmSpaceAddinfo, "'", "");
$parmSpaceAddinfo = fnStringChg($parmSpaceAddinfo, "\"", "");
$parmSpaceAddinfo = fnStringChg($parmSpaceAddinfo, "<", "");
$parmSpaceAddinfo = fnStringChg($parmSpaceAddinfo, ">", "");
$lcEnterDate = fnTodayDate("");
$lcEnterHms = fnTodayTime("");
/*//기존의 등록된 활동사진을 삭제해준다
$qry = "SELECT filename ";
$qry = $qry."FROM fr_member ";
$qry = $qry."WHERE 1=1 ";
$qry = $qry." AND seq='".$user_seq."' ";
$rs1 = mysql_query($qry, $dbConn);
if(!$rs1){die(mysql_error($dbConn));}
$totrow1 = mysql_num_rows($rs1);
if($row1 = mysql_fetch_array($rs1)){
$lcFilename = $row1[filename];
$lcFilename = fnStringChg($lcFilename, " ", "");
if($lcFilename!=null && $lcFilename!=""){
fncRootDelFile($lcDocumentRoot, "/upload/member_photo", $lcFilename);
}
}else{
;
}*/
//홍보자료번호 차번 생성
$qry = "SELECT ( IFNULL(MAX(seq),0) +1) seq ";
$qry = $qry."FROM svc_hongbo ";
$qry = $qry."WHERE 1=1 ";
$rs1 = mysql_query($qry, $dbConn);
if(!$rs1){die(mysql_error($dbConn));}
$totrow1 = mysql_num_rows($rs1);
if($row1 = mysql_fetch_array($rs1)){
$lcSeq = $row1[seq];
}
//홍보 키 생성
$lcTimestamp = time();
//echo "timestamp : ".$lcTimestamp."<br>";
if(strlen($lcTimestamp)==10){
$lcTimestamp = substr($lcTimestamp, -6); //뒤에서 6자리
}else if(strlen($lcTimestamp)==9){
$lcTimestamp = substr($lcTimestamp, -6); //뒤에서 6자리
}else if(strlen($lcTimestamp)==8){
$lcTimestamp = substr($lcTimestamp, -6); //뒤에서 6자리
}else if(strlen($lcTimestamp)==7){
$lcTimestamp = substr($lcTimestamp, -6); //뒤에서 6자리
}else if(strlen($lcTimestamp)==6){
$lcTimestamp = substr($lcTimestamp, -6); //뒤에서 6자리
}else if(strlen($lcTimestamp)==5){
$lcTimestamp = substr($lcTimestamp, -5)."0"; //뒤에서 6자리
}
$lcRand = rand(1, 99999)."";
if($lcRand==null)$lcRand="";
if(strlen($lcRand)==0){
$lcRand = "00000".$lcRand;
}else if(strlen($lcRand)==1){
$lcRand = "0000".$lcRand;
}else if(strlen($lcRand)==2){
$lcRand = "000".$lcRand;
}else if(strlen($lcRand)==3){
$lcRand = "00".$lcRand;
}else if(strlen($lcRand)==4){
$lcRand = "0".$lcRand;
}else if(strlen($lcRand)==5){
$lcRand = "".$lcRand;
}
$lcHongboKey = "";
$lcHongboKey=$lcHongboKey.$lcTimestamp;
$lcHongboKey=$lcHongboKey.$lcRand;
//등록
$qry = "INSERT INTO svc_hongbo (";
$qry = $qry."seq, sosok_category, ";
$qry = $qry."hb_name, ";
$qry = $qry."hb_desc, ";
$qry = $qry."space_sido, ";
$qry = $qry."space_addinfo, ";
$qry = $qry."write_seq, ";
$qry = $qry."q_hp, q_mail, attend_price, ";
$qry = $qry."enter_date, enter_hms, ";
$qry = $qry."visit, show_yn, ";
$qry = $qry."img1, img2, img3, ";
$qry = $qry."img4, img5, img6, ";
$qry = $qry."proc_state, hongbo_key ";
$qry = $qry.") ";
$qry = $qry."VALUES ( ";
$qry = $qry."'".$lcSeq."', '".$parmCategory."', ";
$qry = $qry."'".$parmHongboName."', ";
$qry = $qry."'".$parmHongboDesc."', ";
$qry = $qry."'".$parmSpaceSido."', ";
$qry = $qry."'".$parmSpaceAddinfo."', ";
$qry = $qry."'".$parmLoginSeq."', ";
$qry = $qry."'".$parmHp."', '', '".$parmAttendPrice."', ";
$qry = $qry."'".$lcEnterDate."', '".$lcEnterHms."', ";
$qry = $qry."'0', 'Y', ";
$qry = $qry."'".$flFileName1."', '".$flFileName2."', '".$flFileName3."', ";
$qry = $qry."'".$flFileName4."', '".$flFileName5."', '".$flFileName6."', ";
$qry = $qry."'01', '".$lcHongboKey."' ";
$qry = $qry.")";
mysql_query($qry, $dbConn);
?>
<?
//DATABASE STOP
include_once($lcTmplGvPathSet."/config/database/dbstop.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?//줌 기능 없이 그대로 표현?>
<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no;" />
<title><?=$gvTextTitle?></title>
<link rel="stylesheet" href="/resource/css/style.css" type="text/css" media="all" />
</head>
<script language="javascript" src="/resource/js/link.js"></script>
<script language="javascript" src="/resource/js/flash.js"></script>
<script language="javascript" src="/resource/js/Cookie.js"></script>
<script language="javascript" src="/resource/js/file.js"></script>
<script language="javascript" src="/resource/js/string.js"></script>
<script language="javascript" src="/resource/js/numeric.js"></script>
<script language="javascript" src="/resource/js/image.js"></script>
<script type="text/javascript" src="/resource/js/image_lightbox.js"></script>
<script type="text/javascript" src="/resource/js/minipop_sideview.js"></script>
<?
if($sess_member_id==""){
echo "<script language='javascript'>";
echo "top.location.href='/mb/login.php';";
echo "</script>";
exit();
}
?>
<script>
alert("홍보자료가 등록 되었어요~");
location.href="./main.php";
</script>
<body
style="margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;"
bgcolor="#FFFF00">
홍보자료가 등록 되었어요
</BODY>
</HTML>
댓글 없음:
댓글 쓰기