Views/UserCenter/UploadAvatar.ashx

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<%@ WebHandler Language="C#" Class="UploadAvatar" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using MicroDBHelper;
using MicroPublicHelper;
using MicroUserHelper;
using MicroAuthHelper;

public class UploadAvatar : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        MicroAuth.CheckLogin();

        string msg = MicroPublic.GetMsg("UploadFailed");
        string flag = "{\"code\": 0,\"msg\": \"" + msg + "\",\"data\": { \"src\": \"\"}}";
        string filePath = "~/Resource/UploadFiles/Images/Avatar/";

        if (((MicroUserInfo)context.Session["UserInfo"]).GetIsLogin())
        {
            try
            {
                HttpFileCollection files = context.Request.Files;
                if (files.Count > 0)
                {
                    //设置文件名
                    string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmssff") + "_" + System.IO.Path.GetFileName(files[0].FileName);
                    //保存文件
                    filePath += fileNewName;
                    files[0].SaveAs(context.Server.MapPath(filePath));

                    string _sql = "update UserInfo set Avatar=@Avatar where UID=@UID";
                    SqlParameter[] _sp = { new SqlParameter("@Avatar",SqlDbType.VarChar,200),
                                       new SqlParameter("@UID",SqlDbType.Int)   };
                    _sp[0].Value = filePath;
                    _sp[1].Value = ((MicroUserInfo)context.Session["UserInfo"]).UID;


                    if (MsSQLDbHelper.ExecuteSql(_sql, _sp) > 0)
                        ((MicroUserInfo)context.Session["UserInfo"]).Avatar = filePath;

                    msg = MicroPublic.GetMsg("Upload");
                    flag = "{\"code\": " + files.Count + ",\"msg\": \"" + msg + "\",\"data\": { \"src\": \"" + filePath + "\"}}";
                }

            }
            catch { }
            context.Response.Write(flag);
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
后面还有 2 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。