From 32e3dcff7cf7a85a1347f04556bb716fc32f93d4 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 22 Sep 2018 03:05:58 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + hwe/j_image_upload.php | 109 +++++++++++++++++++++++++++++++++++++++++ hwe/js/dipcenter.js | 49 +++++++++++++++++- 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 hwe/j_image_upload.php diff --git a/.gitignore b/.gitignore index 61948b4b..259ae034 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ d_shared d_pic/*.jpg d_pic/*.gif d_pic/*.png +d_pic/uploaded_image d_setting/*.php */d_setting/*.php diff --git a/hwe/j_image_upload.php b/hwe/j_image_upload.php new file mode 100644 index 00000000..9eca08bf --- /dev/null +++ b/hwe/j_image_upload.php @@ -0,0 +1,109 @@ +setReadOnly(); +$userID = $session::getUserID(); +$serverID = UniqueConst::$serverID; + +$image = $_FILES['img']; +switch ($image['error']) { + case UPLOAD_ERR_OK: + break; + case UPLOAD_ERR_NO_FILE: + Json::die([ + 'result'=>false, + 'reason'=>'파일이 없습니다.' + ]); + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + Json::die([ + 'result'=>false, + 'reason'=>'업로드된 파일이 지나치게 큽니다.' + ]); + default: + Json::die([ + 'result'=>false, + 'reason'=>'업로드되지 않았습니다.' + ]); +} + +if(!is_uploaded_file($image['tmp_name'])) { + Json::die([ + 'result'=>false, + 'reason'=>'제대로 파일이 업로드되지 않았습니다.' + ]); +} + +if($image['size'] > 1048576) { + //파일크기 검사 + Json::die([ + 'result'=>false, + 'reason'=>'1MB 이하로 올려주세요!' + ]); +} + +$size = getImageSize($image['tmp_name']); + +$imageType = $size[2]; +$availableImageType = array('.jpg'=>IMAGETYPE_JPEG, '.png'=>IMAGETYPE_PNG, '.gif'=>IMAGETYPE_GIF); +$newExt = array_search($imageType, $availableImageType, true); + +if(!$newExt) { + Json::die([ + 'result'=>false, + 'reason'=>'jpg, gif, png 파일이 아닙니다!' + ]); +} + +$db = RootDB::db(); +$imgStor = KVStorage::getStorage($db, 'img_storage'); + +$picName = hash_file('md5', $image['tmp_name']); +$newPicName = "$picName$newExt"; + +$destDir = AppConf::getUserIconPathFS().'/uploaded_image'; +$dest = $destDir.'/'.$newPicName; + +if(!file_exists($dest)){ + if (!file_exists($destDir)) { + mkdir($destDir); + } + if(!is_dir($destDir)) { + Json::die([ + 'result'=>false, + 'reason'=>'버그! 업로드 경로 확인!' + ]); + } + if(!is_writable($destDir)){ + Json::die([ + 'result'=>false, + 'reason'=>'버그! 업로드 권한 확인!' + ]); + } + + $dest = $destDir.'/'.$newPicName; + + if(!move_uploaded_file($image['tmp_name'], $dest)) { + Json::die([ + 'result'=>false, + 'reason'=>'업로드에 실패했습니다!' + ]); + } +} + +$storedStatus = $imgStor->$newPicName??[]; +$imgKey = "$serverID:$userID"; +if(!key_exists($imgKey, $storedStatus)){ + $storedStatus[$imgKey] = TimeUtil::DatetimeNow(); +} + +$imgStor->$newPicName = $storedStatus; + +Json::die([ + 'result'=>true, + 'reason'=>'성공', + 'path'=>AppConf::getUserIconPathWeb().'/uploaded_image/'.$newPicName +]); \ No newline at end of file diff --git a/hwe/js/dipcenter.js b/hwe/js/dipcenter.js index 4f9fcf4b..f225e4e9 100644 --- a/hwe/js/dipcenter.js +++ b/hwe/js/dipcenter.js @@ -15,6 +15,12 @@ jQuery(function($){ function enableEditor(){ editMode = true; $cancelEdit.show(); + + var inputText = $noticeInput.val(); + if(!inputText || inputText == '

'){ + inputText = '


'; + } + console.log(inputText); $editForm.removeClass('viewer').summernote({ minHeight:200, maxHeight:null, @@ -33,8 +39,49 @@ jQuery(function($){ ], fontNames: ['맑은 고딕', 'Nanum Gothic', 'Nanum Myeongjo', 'Nanum Pen Script', '굴림', '굴림체', '바탕', '바탕체', '궁서', '궁서체'], fontSizes: ['8', '9', '10', '11', '12', '14', '16', '20', '24', '28', '32', '36', '40', '46', '52', '60'], + callbacks: { + onImageUpload: function(files) { + $editForm.summernote('saveRange'); + if(files.length == 0){ + alert('업로드된 파일이 없습니다.'); + return false; + } - }).summernote('code', $noticeInput.val()); + var formData = new FormData(); + formData.append('img', files[0]); + $editForm.summernote("pasteHtml", ''); + + $.ajax({ + type:'post', + url:'j_image_upload.php', + dataType:'json', + contentType: false, + processData:false, + data:formData + }).then(function(result){ + if(!result.result){ + alert(result.reason); + return; + } + + console.log($editForm.summernote('code')); + if($editForm.summernote('isEmpty')){ + + console.log('haha?'); + var $img = $(''); + $img.attr('src', result.path); + $editForm.summernote('code', $img); + return; + } + + $editForm.summernote("insertImage", result.path, result.path); + + },function(){ + alert('알 수 없는 이유로 아이콘 업로드를 실패했습니다.'); + }); + } + } + }).summernote('code', inputText); } function disableEditor(){