diff --git a/src/admin/api.php b/src/admin/api.php index 34d26f3b..f6d89a24 100644 --- a/src/admin/api.php +++ b/src/admin/api.php @@ -358,13 +358,25 @@ if ($action === 'is_need_check_code') { $activepath = $cfg_image_dir; $allowedTypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp"); $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); $imgSize = getimagesize($uploadedFile); if (!in_array($fileType, $allowedTypes) || !$imgSize) { echo json_encode(array( "code" => -1, - "msg" => "仅支持图片格式文件", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "仅支持图片格式文件", + ), )); exit; } @@ -384,8 +396,10 @@ if ($action === 'is_need_check_code') { $fullfilename = $cfg_basedir.$activepath."/".$filename; move_uploaded_file($_FILES["file"]["tmp_name"], $fullfilename) or die(json_encode(array( "code" => -1, - "msg" => "上传失败", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "上传失败", + ), ))); $info = ''; $sizes[0] = 0; diff --git a/src/admin/dialog/select_images_post.php b/src/admin/dialog/select_images_post.php index f5f2dc7c..427fdfe5 100644 --- a/src/admin/dialog/select_images_post.php +++ b/src/admin/dialog/select_images_post.php @@ -10,6 +10,7 @@ */ require_once(dirname(__FILE__)."/config.php"); require_once(DEDEINC."/image.func.php"); +define("DEDE_DIALOG_UPLOAD", true); if (empty($activepath)) { $activepath = ''; $activepath = str_replace('.', '', $activepath); diff --git a/src/admin/dialog/select_soft_post.php b/src/admin/dialog/select_soft_post.php index 2100dd5d..e6f0937a 100644 --- a/src/admin/dialog/select_soft_post.php +++ b/src/admin/dialog/select_soft_post.php @@ -14,6 +14,7 @@ if (!isset($cfg_basedir)) { if (empty($uploadfile)) $uploadfile = ''; if (empty($uploadmbtype)) $uploadmbtype = '软件类型'; if (empty($bkurl)) $bkurl = 'select_soft.php'; +define("DEDE_DIALOG_UPLOAD", true); $CKEditorFuncNum = (isset($CKEditorFuncNum)) ? $CKEditorFuncNum : 1; $newname = (empty($newname) ? '' : preg_replace("#[\\ \"\*\?\t\r\n<>':\/|]#", "", $newname)); $uploadfile = isset($imgfile) && empty($uploadfile) ? $imgfile : $uploadfile; diff --git a/src/admin/templets/album_add.htm b/src/admin/templets/album_add.htm index 05dffac0..8081271f 100644 --- a/src/admin/templets/album_add.htm +++ b/src/admin/templets/album_add.htm @@ -404,10 +404,12 @@ // console.log(result) addImage(result.data, 0); $("#iptAlbumImages").val(''); + } else { + ShowMsg(result.error.message); } }, error: function (xhr, status, error) { - alert(error); //处理上传失败后的回调 + ShowMsg(error); //处理上传失败后的回调 } }); } diff --git a/src/admin/templets/album_edit.htm b/src/admin/templets/album_edit.htm index 6a6a17a1..36b444c0 100644 --- a/src/admin/templets/album_edit.htm +++ b/src/admin/templets/album_edit.htm @@ -439,10 +439,12 @@ $(`input[name='imgurl${idx}']`).val(result.data); $(`input[name='imgddurl${idx}']`).val(result.data); $("#lit"+idx).attr('src', result.data); + } else { + ShowMsg(result.error.message); } }, error: function (xhr, status, error) { - alert(error); //处理上传失败后的回调 + ShowMsg(error); //处理上传失败后的回调 } }); }) @@ -463,10 +465,12 @@ // console.log(result) addImage(result.data, 0); $("#iptAlbumImages").val(''); + } else { + ShowMsg(result.error.message); } }, error: function (xhr, status, error) { - alert(error); //处理上传失败后的回调 + ShowMsg(error); //处理上传失败后的回调 } }); } diff --git a/src/static/web/js/diy.js b/src/static/web/js/diy.js index cdee70e5..bfd006bc 100644 --- a/src/static/web/js/diy.js +++ b/src/static/web/js/diy.js @@ -26,7 +26,7 @@ function SelectImage(sform, stype) { if (result.code === 0) { $(ipt).val(result.data); } else { - ShowMsg("文件上传失败,错误原因:"+result.msg); + ShowMsg("文件上传失败,错误原因:"+result.error.message); } }, error: function (xhr, status, error) { diff --git a/src/static/web/js/user.js b/src/static/web/js/user.js index 8c6d36bf..ec392404 100644 --- a/src/static/web/js/user.js +++ b/src/static/web/js/user.js @@ -37,7 +37,7 @@ function SelectFile(sform, stype) { if (result.code === 0) { $(ipt).val(result.data); } else { - ShowMsg("文件上传失败,错误原因:"+result.msg); + ShowMsg("文件上传失败,错误原因:"+result.error.message); } }, error: function (xhr, status, error) { diff --git a/src/system/common.func.php b/src/system/common.func.php index 8216d681..d41343b9 100755 --- a/src/system/common.func.php +++ b/src/system/common.func.php @@ -326,6 +326,15 @@ if (!function_exists('file_put_contents')) { */ 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') { echo json_encode(array( "code"=>0, diff --git a/src/user/api.php b/src/user/api.php index ac81da7e..0846a943 100755 --- a/src/user/api.php +++ b/src/user/api.php @@ -62,16 +62,20 @@ if ($action === 'is_need_check_code') { if (!$cfg_ml->IsLogin()) { echo json_encode(array( "code" => -1, - "msg" => "请登录会员中心", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "请登录会员中心", + ), )); exit; } if ($cfg_ml->CheckUserSpaceIsFull()) { echo json_encode(array( "code" => -1, - "msg" => "您的空间已满,禁止上传新文件", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "您的空间已满,禁止上传新文件", + ), )); exit; } @@ -101,20 +105,35 @@ if ($action === 'is_need_check_code') { } else { echo json_encode(array( "code" => -1, - "msg" => "未定义文件类型", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "未定义文件类型", + ), )); exit; } $ff = isset($_FILES['file'])? $_FILES['file'] : $_FILES['imgfile']; $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); if (!in_array($fileType, $allowedTypes)) { echo json_encode(array( "code" => -1, - "msg" => "不支持该文件格式", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "不支持该文件格式", + ), )); + exit; } //获取扩展名 @@ -126,8 +145,10 @@ if ($action === 'is_need_check_code') { if (!$imgSize) { echo json_encode(array( "code" => -1, - "msg" => "无法获取图片正常尺寸", - "data" => null, + "uploaded" => 0, + "error" => array( + "message" => "无法获取图片正常尺寸", + ), )); exit; } @@ -146,7 +167,10 @@ if ($action === 'is_need_check_code') { if ($fsize > ($cfg_max_face * 1024)) { echo json_encode(array( "code" => -1, - "msg" => "上传头像不能超过{$cfg_max_face}KB", + "uploaded" => 0, + "error" => array( + "message" => "上传头像不能超过{$cfg_max_face}KB", + ), $rkey => null, )); exit; @@ -155,7 +179,10 @@ if ($action === 'is_need_check_code') { if ($fsize > ($cfg_mb_upload_size * 1024)) { echo json_encode(array( "code" => -1, - "msg" => "上传文件不能超过{$cfg_mb_upload_size}KB", + "uploaded" => 0, + "error" => array( + "message" => "上传头像不能超过{$cfg_max_face}KB", + ), $rkey => null, )); exit; @@ -196,7 +223,10 @@ if ($action === 'is_need_check_code') { } catch (ImageResizeException $e) { echo json_encode(array( "code" => -1, - "msg" => "自动裁剪图片失败", + "uploaded" => 0, + "error" => array( + "message" => "自动裁剪图片失败", + ), $rkey => null, )); } @@ -211,7 +241,10 @@ if ($action === 'is_need_check_code') { } else { echo json_encode(array( "code" => -1, - "msg" => "上传失败", + "uploaded" => 0, + "error" => array( + "message" => "上传失败", + ), $rkey => null, )); } diff --git a/src/user/templets/edit_baseinfo.htm b/src/user/templets/edit_baseinfo.htm index af073ba8..42deb801 100755 --- a/src/user/templets/edit_baseinfo.htm +++ b/src/user/templets/edit_baseinfo.htm @@ -158,7 +158,7 @@ $("#face").attr('src', result.data); $("#newface").val(result.data); } else { - ShowMsg(result.msg); + ShowMsg(result.error.message); } }, error: function (xhr, status, error) { diff --git a/src/user/templets/widget_litpic.htm b/src/user/templets/widget_litpic.htm index 74f99a00..15ca72d5 100644 --- a/src/user/templets/widget_litpic.htm +++ b/src/user/templets/widget_litpic.htm @@ -18,7 +18,7 @@ $("#imgLitpic").attr('src', result.data); $("#litpic").val(result.data); } else { - ShowMsg(result.msg); + ShowMsg(result.error.message); } }, error: function (xhr, status, error) {