이미지 업로드 기능 추가
This commit is contained in:
@@ -28,6 +28,7 @@ d_shared
|
|||||||
d_pic/*.jpg
|
d_pic/*.jpg
|
||||||
d_pic/*.gif
|
d_pic/*.gif
|
||||||
d_pic/*.png
|
d_pic/*.png
|
||||||
|
d_pic/uploaded_image
|
||||||
|
|
||||||
d_setting/*.php
|
d_setting/*.php
|
||||||
*/d_setting/*.php
|
*/d_setting/*.php
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
include 'lib.php';
|
||||||
|
include 'func.php';
|
||||||
|
|
||||||
|
$session = Session::requireGameLogin([])->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
|
||||||
|
]);
|
||||||
+48
-1
@@ -15,6 +15,12 @@ jQuery(function($){
|
|||||||
function enableEditor(){
|
function enableEditor(){
|
||||||
editMode = true;
|
editMode = true;
|
||||||
$cancelEdit.show();
|
$cancelEdit.show();
|
||||||
|
|
||||||
|
var inputText = $noticeInput.val();
|
||||||
|
if(!inputText || inputText == '<p></p>'){
|
||||||
|
inputText = '<p><br></p>';
|
||||||
|
}
|
||||||
|
console.log(inputText);
|
||||||
$editForm.removeClass('viewer').summernote({
|
$editForm.removeClass('viewer').summernote({
|
||||||
minHeight:200,
|
minHeight:200,
|
||||||
maxHeight:null,
|
maxHeight:null,
|
||||||
@@ -33,8 +39,49 @@ jQuery(function($){
|
|||||||
],
|
],
|
||||||
fontNames: ['맑은 고딕', 'Nanum Gothic', 'Nanum Myeongjo', 'Nanum Pen Script', '굴림', '굴림체', '바탕', '바탕체', '궁서', '궁서체'],
|
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'],
|
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>');
|
||||||
|
$img.attr('src', result.path);
|
||||||
|
$editForm.summernote('code', $img);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editForm.summernote("insertImage", result.path, result.path);
|
||||||
|
|
||||||
|
},function(){
|
||||||
|
alert('알 수 없는 이유로 아이콘 업로드를 실패했습니다.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).summernote('code', inputText);
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableEditor(){
|
function disableEditor(){
|
||||||
|
|||||||
Reference in New Issue
Block a user