国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

167 行
5.8KB

  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 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. if ($action === 'is_need_check_code') {
  15. $isNeed = $cfg_ml->isNeedCheckCode($userid);
  16. echo json_encode(array(
  17. "code" => 0,
  18. "msg" => "",
  19. "data" => array(
  20. "isNeed" => $isNeed,
  21. ),
  22. ));
  23. exit;
  24. } else if ($action === 'get_old_email') {
  25. $oldpwd = isset($oldpwd)? $oldpwd : '';
  26. if (empty($oldpwd)) {
  27. echo json_encode(array(
  28. "code" => -1,
  29. "msg" => "旧密码不能为空",
  30. "data" => null,
  31. ));
  32. exit;
  33. }
  34. $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='".$cfg_ml->M_ID."' ");
  35. if (function_exists('password_hash') && !empty($row['pwd_new'])) {
  36. if (!is_array($row) || !password_verify($oldpwd, $row['pwd_new'])) {
  37. echo json_encode(array(
  38. "code" => -1,
  39. "msg" => "旧密码校验错误",
  40. "data" => null,
  41. ));
  42. exit;
  43. }
  44. } else {
  45. if (!is_array($row) || $row['pwd'] != md5($oldpwd)) {
  46. echo json_encode(array(
  47. "code" => -1,
  48. "msg" => "旧密码校验错误",
  49. "data" => null,
  50. ));
  51. exit;
  52. }
  53. }
  54. echo json_encode(array(
  55. "code" => 0,
  56. "msg" => "",
  57. "data" => array(
  58. "email" => $row['email'],
  59. ),
  60. ));
  61. } else if ($action === 'upload') {
  62. if (!$cfg_ml->IsLogin()) {
  63. echo json_encode(array(
  64. "code" => -1,
  65. "msg" => "未登录",
  66. "data" => null,
  67. ));
  68. exit;
  69. }
  70. $target_dir = "uploads/";//上传目录
  71. $type = isset($type)? $type : '';
  72. $allowedTypes = array('image/png', 'image/jpg', 'image/jpeg');
  73. $uploadedFile = $_FILES['file']['tmp_name'];
  74. $fileType = mime_content_type($uploadedFile);
  75. $imgSize = getimagesize($uploadedFile);
  76. if (!in_array($fileType, $allowedTypes) || !$imgSize) {
  77. echo json_encode(array(
  78. "code" => -1,
  79. "msg" => "仅支持图片格式文件",
  80. "data" => null,
  81. ));
  82. exit;
  83. }
  84. if (!is_dir($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}")) {
  85. MkdirAll($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}", $cfg_dir_purview);
  86. CloseFtp();
  87. }
  88. if ($type === "face") {
  89. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/newface.png";//上传文件名
  90. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/newface.png";
  91. } else {
  92. $nowtme = time();
  93. $rnd = $nowtme.'-'.mt_rand(1000,9999);
  94. $target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/".$rnd.".png";
  95. $fsize = filesize($_FILES["file"]["tmp_name"]);
  96. $target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/".$rnd.".png";
  97. $row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$target_url' AND mid='".$cfg_ml->M_ID."'; ");
  98. $uptime = time();
  99. if (is_array($row)) {
  100. $query = "UPDATE `#@__uploads` SET mediatype=1,width='{$imgSize[0]}',height='{$imgSize[1]}',filesize='{$fsize}',uptime='$uptime' WHERE aid='{$row['aid']}'; ";
  101. $dsql->ExecuteNoneQuery($query);
  102. } else {
  103. $inquery = "INSERT INTO `#@__uploads`(url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('$target_url','1','".$imgSize[0]."','".$imgSize[1]."','0','".$fsize."','$uptime','".$cfg_ml->M_ID."'); ";
  104. $dsql->ExecuteNoneQuery($inquery);
  105. }
  106. }
  107. if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
  108. require_once DEDEINC."/libraries/imageresize.class.php";
  109. try{
  110. $image = new ImageResize($target_file);
  111. if ($type === "face") {
  112. $image->crop(150, 150);
  113. } else {
  114. $image->resize($cfg_ddimg_width, $cfg_ddimg_height);
  115. }
  116. $image->save($target_file);
  117. echo json_encode(array(
  118. "code" => 0,
  119. "msg" => "上传成功",
  120. "data" => $target_url,
  121. ));
  122. } catch (ImageResizeException $e) {
  123. echo json_encode(array(
  124. "code" => -1,
  125. "msg" => "图片自动裁剪失败",
  126. "data" => null,
  127. ));
  128. }
  129. } else {
  130. echo json_encode(array(
  131. "code" => -1,
  132. "msg" => "上传失败",
  133. "data" => null,
  134. ));
  135. }
  136. } else {
  137. $format = isset($format) ? "json" : "";
  138. if (!$cfg_ml->IsLogin()) {
  139. if ($format === 'json') {
  140. echo json_encode(array(
  141. "code" => -1,
  142. "msg" => "未登录",
  143. "data" => null,
  144. ));
  145. } else {
  146. echo "";
  147. }
  148. exit;
  149. }
  150. $uid = $cfg_ml->M_LoginID;
  151. !$cfg_ml->fields['face'] && $face = ($cfg_ml->fields['sex'] == '女') ? 'dfgirl' : 'dfboy';
  152. $facepic = empty($face) ? $cfg_ml->fields['face'] : $GLOBALS['cfg_memberurl'].'/templets/images/'.$face.'.png';
  153. if ($format === 'json') {
  154. echo json_encode(array(
  155. "code" => 200,
  156. "msg" => "",
  157. "data" => array(
  158. "username" => $cfg_ml->M_UserName,
  159. "myurl" => $myurl,
  160. "facepic" => $facepic,
  161. "memberurl" => $cfg_memberurl,
  162. ),
  163. ));
  164. exit;
  165. }
  166. }
  167. ?>