国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 anni fa
1 anno fa
2 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /**
  3. * @version $id:api.php 8:38 2010年7月9日 tianya $
  4. * @package DedeBIZ.User
  5. * @copyright Copyright (c) 2022 DedeBIZ.COM
  6. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  7. * @link https://www.dedebiz.com
  8. */
  9. define('AJAXLOGIN', TRUE);
  10. define('IS_DEDEAPI', TRUE);
  11. require_once(dirname(__FILE__)."/config.php");
  12. AjaxHead();
  13. $action = isset($action)? $action : '';
  14. $rkey = $ck == 1? "url" : "data";
  15. if ($action === 'is_need_check_code') {
  16. $isNeed = $cfg_ml->isNeedCheckCode($userid);
  17. echo json_encode(array(
  18. "code" => 0,
  19. "msg" => "",
  20. "data" => array(
  21. "isNeed" => $isNeed,
  22. ),
  23. ));
  24. exit;
  25. } else if ($action === 'get_old_email') {
  26. $oldpwd = isset($oldpwd)? $oldpwd : '';
  27. if (empty($oldpwd)) {
  28. echo json_encode(array(
  29. "code" => -1,
  30. "msg" => "旧密码不能为空",
  31. "data" => null,
  32. ));
  33. exit;
  34. }
  35. $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='".$cfg_ml->M_ID."' ");
  36. if (function_exists('password_hash') && !empty($row['pwd_new'])) {
  37. if (!is_array($row) || !password_verify($oldpwd, $row['pwd_new'])) {
  38. echo json_encode(array(
  39. "code" => -1,
  40. "msg" => "旧密码校验错误",
  41. "data" => null,
  42. ));
  43. exit;
  44. }
  45. } else {
  46. if (!is_array($row) || $row['pwd'] != md5($oldpwd)) {
  47. echo json_encode(array(
  48. "code" => -1,
  49. "msg" => "旧密码校验错误",
  50. "data" => null,
  51. ));
  52. exit;
  53. }
  54. }
  55. echo json_encode(array(
  56. "code" => 0,
  57. "msg" => "",
  58. "data" => array(
  59. "email" => $row['email'],
  60. ),
  61. ));
  62. } else if ($action === 'upload') {
  63. if (!$cfg_ml->IsLogin()) {
  64. echo json_encode(array(
  65. "code" => -1,
  66. "uploaded" => 0,
  67. "error" => array(
  68. "message" => "请登录会员中心",
  69. ),
  70. ));
  71. exit;
  72. }
  73. if ($cfg_ml->CheckUserSpaceIsFull()) {
  74. echo json_encode(array(
  75. "code" => -1,
  76. "uploaded" => 0,
  77. "error" => array(
  78. "message" => "您的空间已满,禁止上传新文件",
  79. ),
  80. ));
  81. exit;
  82. }
  83. $target_dir = "uploads/";//上传目录
  84. $type = isset($type)? $type : '';
  85. //获取允许的扩展
  86. $mediatype = 0;
  87. $allowedTypes = array();
  88. if ($type == 'litpic' || $type == 'face') {
  89. $mediatype = 1;
  90. $imgtypes = explode("|", $cfg_imgtype);
  91. foreach ($imgtypes as $value) {
  92. $allowedTypes[] = GetMimeTypeOrExtension($value);
  93. }
  94. } else if ($type == 'soft') {
  95. $mediatype = 4;
  96. $softtypes = explode("|", $cfg_softtype);
  97. foreach ($softtypes as $value) {
  98. $allowedTypes[] = GetMimeTypeOrExtension($value);
  99. }
  100. } else if ($type == 'media') {
  101. $mediatype = 3;
  102. $mediatypes = explode("|", $cfg_mediatype);
  103. foreach ($mediatypes as $value) {
  104. $allowedTypes[] = GetMimeTypeOrExtension($value);
  105. }
  106. } else {
  107. echo json_encode(array(
  108. "code" => -1,
  109. "uploaded" => 0,
  110. "error" => array(
  111. "message" => "未定义文件类型",
  112. ),
  113. ));
  114. exit;
  115. }
  116. $ff = isset($_FILES['file'])? $_FILES['file'] : $_FILES['imgfile'];
  117. $uploadedFile = $ff['tmp_name'];
  118. if (!function_exists('mime_content_type')) {
  119. echo json_encode(array(
  120. "code" => -1,
  121. "uploaded" => 0,
  122. "error" => array(
  123. "message" => "系统不支持fileinfo组件,建议php.ini中开启",
  124. ),
  125. ));
  126. exit;
  127. }
  128. $fileType = mime_content_type($uploadedFile);
  129. if (!in_array($fileType, $allowedTypes)) {
  130. echo json_encode(array(
  131. "code" => -1,
  132. "uploaded" => 0,
  133. "error" => array(
  134. "message" => "不支持该文件格式",
  135. ),
  136. ));
  137. exit;
  138. }
  139. //获取扩展名
  140. $exts = GetMimeTypeOrExtension($fileType, 1);
  141. $width = 0;
  142. $height = 0;
  143. if ($mediatype === 1) {
  144. $imgSize = getimagesize($uploadedFile);
  145. if (!$imgSize) {
  146. echo json_encode(array(
  147. "code" => -1,
  148. "uploaded" => 0,
  149. "error" => array(
  150. "message" => "无法获取图片正常尺寸",
  151. ),
  152. ));
  153. exit;
  154. }
  155. $width = $imgSize[0];
  156. $height = $imgSize[1];
  157. }
  158. if (!is_dir($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}")) {
  159. MkdirAll($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}", $cfg_dir_purview);
  160. }
  161. //头像特殊处理
  162. $fsize = filesize($ff["tmp_name"]);
  163. if ($type === "face") {
  164. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/newface.png";
  165. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/newface.png";
  166. if ($fsize > ($cfg_max_face * 1024)) {
  167. echo json_encode(array(
  168. "code" => -1,
  169. "uploaded" => 0,
  170. "error" => array(
  171. "message" => "上传头像不能超过{$cfg_max_face}KB",
  172. ),
  173. $rkey => null,
  174. ));
  175. exit;
  176. }
  177. } else {
  178. if ($fsize > ($cfg_mb_upload_size * 1024)) {
  179. echo json_encode(array(
  180. "code" => -1,
  181. "uploaded" => 0,
  182. "error" => array(
  183. "message" => "上传头像不能超过{$cfg_max_face}KB",
  184. ),
  185. $rkey => null,
  186. ));
  187. exit;
  188. }
  189. $nowtme = time();
  190. $rnd = $nowtme.'-'.mt_rand(1000, 9999);
  191. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/".$rnd.".".$exts;
  192. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/".$rnd.".".$exts;
  193. $row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$target_url' AND mid='".$cfg_ml->M_ID."'; ");
  194. $uptime = time();
  195. if (is_array($row)) {
  196. $query = "UPDATE `#@__uploads` SET mediatype={$mediatype},width='{$width}',height='{$height}',filesize='{$fsize}',uptime='$uptime' WHERE aid='{$row['aid']}'; ";
  197. $dsql->ExecuteNoneQuery($query);
  198. } else {
  199. $inquery = "INSERT INTO `#@__uploads`(url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('$target_url','$mediatype','".$width."','".$height."','0','".$fsize."','$uptime','".$cfg_ml->M_ID."'); ";
  200. $dsql->ExecuteNoneQuery($inquery);
  201. }
  202. }
  203. if (move_uploaded_file($ff["tmp_name"], $target_file)) {
  204. if ($mediatype === 1) {
  205. //图片自动裁剪
  206. require_once DEDEINC."/libraries/imageresize.class.php";
  207. try {
  208. $image = new ImageResize($target_file);
  209. if ($type === "face") {
  210. $image->crop(150, 150);
  211. } else {
  212. $image->resize($cfg_ddimg_width, $cfg_ddimg_height);
  213. }
  214. $image->save($target_file);
  215. echo json_encode(array(
  216. "code" => 0,
  217. "uploaded" => 1,
  218. "msg" => "上传成功",
  219. $rkey => $target_url,
  220. ));
  221. } catch (ImageResizeException $e) {
  222. echo json_encode(array(
  223. "code" => -1,
  224. "uploaded" => 0,
  225. "error" => array(
  226. "message" => "自动裁剪图片失败",
  227. ),
  228. $rkey => null,
  229. ));
  230. }
  231. } else {
  232. echo json_encode(array(
  233. "code" => 0,
  234. "uploaded" => 1,
  235. "msg" => "上传成功",
  236. $rkey => $target_url,
  237. ));
  238. }
  239. } else {
  240. echo json_encode(array(
  241. "code" => -1,
  242. "uploaded" => 0,
  243. "error" => array(
  244. "message" => "上传失败",
  245. ),
  246. $rkey => null,
  247. ));
  248. }
  249. } else {
  250. $format = isset($format) ? "json" : "";
  251. if (!$cfg_ml->IsLogin()) {
  252. if ($format === 'json') {
  253. echo json_encode(array(
  254. "code" => -1,
  255. "msg" => "请登录会员中心",
  256. $rkey => null,
  257. ));
  258. } else {
  259. echo "";
  260. }
  261. exit;
  262. }
  263. $uid = $cfg_ml->M_LoginID;
  264. !$cfg_ml->fields['face'] && $face = ($cfg_ml->fields['sex'] == '女') ? 'dfgirl' : 'dfboy';
  265. if ($format === 'json') {
  266. echo json_encode(array(
  267. "code" => 200,
  268. "msg" => "",
  269. "data" => array(
  270. "username" => $cfg_ml->M_UserName,
  271. "myurl" => $myurl,
  272. "facepic" => $cfg_ml->fields['face'],
  273. "memberurl" => $cfg_memberurl,
  274. ),
  275. ));
  276. exit;
  277. }
  278. }
  279. ?>