@@ -358,13 +358,25 @@ if ($action === 'is_need_check_code') { | |||||
$activepath = $cfg_image_dir; | $activepath = $cfg_image_dir; | ||||
$allowedTypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp"); | $allowedTypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp"); | ||||
$uploadedFile = $_FILES['file']['tmp_name']; | $uploadedFile = $_FILES['file']['tmp_name']; | ||||
if (!function_exists('mime_content_type')) { | |||||
echo json_encode(array( | |||||
"code" => -1, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "系统不支持fileinfo组件,建议php.ini中开启", | |||||
), | |||||
)); | |||||
exit; | |||||
} | |||||
$fileType = mime_content_type($uploadedFile); | $fileType = mime_content_type($uploadedFile); | ||||
$imgSize = getimagesize($uploadedFile); | $imgSize = getimagesize($uploadedFile); | ||||
if (!in_array($fileType, $allowedTypes) || !$imgSize) { | if (!in_array($fileType, $allowedTypes) || !$imgSize) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "仅支持图片格式文件", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "仅支持图片格式文件", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
@@ -384,8 +396,10 @@ if ($action === 'is_need_check_code') { | |||||
$fullfilename = $cfg_basedir.$activepath."/".$filename; | $fullfilename = $cfg_basedir.$activepath."/".$filename; | ||||
move_uploaded_file($_FILES["file"]["tmp_name"], $fullfilename) or die(json_encode(array( | move_uploaded_file($_FILES["file"]["tmp_name"], $fullfilename) or die(json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "上传失败", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "上传失败", | |||||
), | |||||
))); | ))); | ||||
$info = ''; | $info = ''; | ||||
$sizes[0] = 0; | $sizes[0] = 0; | ||||
@@ -10,6 +10,7 @@ | |||||
*/ | */ | ||||
require_once(dirname(__FILE__)."/config.php"); | require_once(dirname(__FILE__)."/config.php"); | ||||
require_once(DEDEINC."/image.func.php"); | require_once(DEDEINC."/image.func.php"); | ||||
define("DEDE_DIALOG_UPLOAD", true); | |||||
if (empty($activepath)) { | if (empty($activepath)) { | ||||
$activepath = ''; | $activepath = ''; | ||||
$activepath = str_replace('.', '', $activepath); | $activepath = str_replace('.', '', $activepath); | ||||
@@ -14,6 +14,7 @@ if (!isset($cfg_basedir)) { | |||||
if (empty($uploadfile)) $uploadfile = ''; | if (empty($uploadfile)) $uploadfile = ''; | ||||
if (empty($uploadmbtype)) $uploadmbtype = '软件类型'; | if (empty($uploadmbtype)) $uploadmbtype = '软件类型'; | ||||
if (empty($bkurl)) $bkurl = 'select_soft.php'; | if (empty($bkurl)) $bkurl = 'select_soft.php'; | ||||
define("DEDE_DIALOG_UPLOAD", true); | |||||
$CKEditorFuncNum = (isset($CKEditorFuncNum)) ? $CKEditorFuncNum : 1; | $CKEditorFuncNum = (isset($CKEditorFuncNum)) ? $CKEditorFuncNum : 1; | ||||
$newname = (empty($newname) ? '' : preg_replace("#[\\ \"\*\?\t\r\n<>':\/|]#", "", $newname)); | $newname = (empty($newname) ? '' : preg_replace("#[\\ \"\*\?\t\r\n<>':\/|]#", "", $newname)); | ||||
$uploadfile = isset($imgfile) && empty($uploadfile) ? $imgfile : $uploadfile; | $uploadfile = isset($imgfile) && empty($uploadfile) ? $imgfile : $uploadfile; | ||||
@@ -404,10 +404,12 @@ | |||||
// console.log(result) | // console.log(result) | ||||
addImage(result.data, 0); | addImage(result.data, 0); | ||||
$("#iptAlbumImages").val(''); | $("#iptAlbumImages").val(''); | ||||
} else { | |||||
ShowMsg(result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
alert(error); //处理上传失败后的回调 | |||||
ShowMsg(error); //处理上传失败后的回调 | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
@@ -439,10 +439,12 @@ | |||||
$(`input[name='imgurl${idx}']`).val(result.data); | $(`input[name='imgurl${idx}']`).val(result.data); | ||||
$(`input[name='imgddurl${idx}']`).val(result.data); | $(`input[name='imgddurl${idx}']`).val(result.data); | ||||
$("#lit"+idx).attr('src', result.data); | $("#lit"+idx).attr('src', result.data); | ||||
} else { | |||||
ShowMsg(result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
alert(error); //处理上传失败后的回调 | |||||
ShowMsg(error); //处理上传失败后的回调 | |||||
} | } | ||||
}); | }); | ||||
}) | }) | ||||
@@ -463,10 +465,12 @@ | |||||
// console.log(result) | // console.log(result) | ||||
addImage(result.data, 0); | addImage(result.data, 0); | ||||
$("#iptAlbumImages").val(''); | $("#iptAlbumImages").val(''); | ||||
} else { | |||||
ShowMsg(result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
alert(error); //处理上传失败后的回调 | |||||
ShowMsg(error); //处理上传失败后的回调 | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
@@ -26,7 +26,7 @@ function SelectImage(sform, stype) { | |||||
if (result.code === 0) { | if (result.code === 0) { | ||||
$(ipt).val(result.data); | $(ipt).val(result.data); | ||||
} else { | } else { | ||||
ShowMsg("文件上传失败,错误原因:"+result.msg); | |||||
ShowMsg("文件上传失败,错误原因:"+result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
@@ -37,7 +37,7 @@ function SelectFile(sform, stype) { | |||||
if (result.code === 0) { | if (result.code === 0) { | ||||
$(ipt).val(result.data); | $(ipt).val(result.data); | ||||
} else { | } else { | ||||
ShowMsg("文件上传失败,错误原因:"+result.msg); | |||||
ShowMsg("文件上传失败,错误原因:"+result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
@@ -326,6 +326,15 @@ if (!function_exists('file_put_contents')) { | |||||
*/ | */ | ||||
function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0) | function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0) | ||||
{ | { | ||||
if (defined('DEDE_DIALOG_UPLOAD') && !isset($GLOBALS['noeditor'])) { | |||||
echo json_encode(array( | |||||
"uploaded"=>0, | |||||
"error"=>array( | |||||
"message" => $msg, | |||||
), | |||||
)); | |||||
return; | |||||
} | |||||
if (isset($GLOBALS['format']) && strtolower($GLOBALS['format'])==='json') { | if (isset($GLOBALS['format']) && strtolower($GLOBALS['format'])==='json') { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code"=>0, | "code"=>0, | ||||
@@ -62,16 +62,20 @@ if ($action === 'is_need_check_code') { | |||||
if (!$cfg_ml->IsLogin()) { | if (!$cfg_ml->IsLogin()) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "请登录会员中心", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "请登录会员中心", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
if ($cfg_ml->CheckUserSpaceIsFull()) { | if ($cfg_ml->CheckUserSpaceIsFull()) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "您的空间已满,禁止上传新文件", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "您的空间已满,禁止上传新文件", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
@@ -101,20 +105,35 @@ if ($action === 'is_need_check_code') { | |||||
} else { | } else { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "未定义文件类型", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "未定义文件类型", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
$ff = isset($_FILES['file'])? $_FILES['file'] : $_FILES['imgfile']; | $ff = isset($_FILES['file'])? $_FILES['file'] : $_FILES['imgfile']; | ||||
$uploadedFile = $ff['tmp_name']; | $uploadedFile = $ff['tmp_name']; | ||||
if (!function_exists('mime_content_type')) { | |||||
echo json_encode(array( | |||||
"code" => -1, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "系统不支持fileinfo组件,建议php.ini中开启", | |||||
), | |||||
)); | |||||
exit; | |||||
} | |||||
$fileType = mime_content_type($uploadedFile); | $fileType = mime_content_type($uploadedFile); | ||||
if (!in_array($fileType, $allowedTypes)) { | if (!in_array($fileType, $allowedTypes)) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "不支持该文件格式", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "不支持该文件格式", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
//获取扩展名 | //获取扩展名 | ||||
@@ -126,8 +145,10 @@ if ($action === 'is_need_check_code') { | |||||
if (!$imgSize) { | if (!$imgSize) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "无法获取图片正常尺寸", | |||||
"data" => null, | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "无法获取图片正常尺寸", | |||||
), | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
@@ -146,7 +167,10 @@ if ($action === 'is_need_check_code') { | |||||
if ($fsize > ($cfg_max_face * 1024)) { | if ($fsize > ($cfg_max_face * 1024)) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "上传头像不能超过{$cfg_max_face}KB", | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "上传头像不能超过{$cfg_max_face}KB", | |||||
), | |||||
$rkey => null, | $rkey => null, | ||||
)); | )); | ||||
exit; | exit; | ||||
@@ -155,7 +179,10 @@ if ($action === 'is_need_check_code') { | |||||
if ($fsize > ($cfg_mb_upload_size * 1024)) { | if ($fsize > ($cfg_mb_upload_size * 1024)) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "上传文件不能超过{$cfg_mb_upload_size}KB", | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "上传头像不能超过{$cfg_max_face}KB", | |||||
), | |||||
$rkey => null, | $rkey => null, | ||||
)); | )); | ||||
exit; | exit; | ||||
@@ -196,7 +223,10 @@ if ($action === 'is_need_check_code') { | |||||
} catch (ImageResizeException $e) { | } catch (ImageResizeException $e) { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "自动裁剪图片失败", | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "自动裁剪图片失败", | |||||
), | |||||
$rkey => null, | $rkey => null, | ||||
)); | )); | ||||
} | } | ||||
@@ -211,7 +241,10 @@ if ($action === 'is_need_check_code') { | |||||
} else { | } else { | ||||
echo json_encode(array( | echo json_encode(array( | ||||
"code" => -1, | "code" => -1, | ||||
"msg" => "上传失败", | |||||
"uploaded" => 0, | |||||
"error" => array( | |||||
"message" => "上传失败", | |||||
), | |||||
$rkey => null, | $rkey => null, | ||||
)); | )); | ||||
} | } | ||||
@@ -158,7 +158,7 @@ | |||||
$("#face").attr('src', result.data); | $("#face").attr('src', result.data); | ||||
$("#newface").val(result.data); | $("#newface").val(result.data); | ||||
} else { | } else { | ||||
ShowMsg(result.msg); | |||||
ShowMsg(result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||
@@ -18,7 +18,7 @@ | |||||
$("#imgLitpic").attr('src', result.data); | $("#imgLitpic").attr('src', result.data); | ||||
$("#litpic").val(result.data); | $("#litpic").val(result.data); | ||||
} else { | } else { | ||||
ShowMsg(result.msg); | |||||
ShowMsg(result.error.message); | |||||
} | } | ||||
}, | }, | ||||
error: function (xhr, status, error) { | error: function (xhr, status, error) { | ||||