• 14阅读
  • 0回复

[Aspxnet交流] APP接口上传图片


会员


发帖
7
楼主  发表于:2018/9/8 19:24
 private void uploadfile(string skey)//接受上传图片
    {
        var db = new DataSqlServer();
        JsonData fhsz = new JsonData();
        fhsz["status"] = -1;
        var re = HttpContext.Current.Request;
        if (re.Files.Count > 0)
        {
            if (skey.Length < 3)
            {
                fhsz["fname"] = "失败!无用户身份";
                HttpContext.Current.Response.Write(fhsz.ToJson());
                return;
            }
            string p = System.Text.Encoding.UTF8.GetString(re.BinaryRead(re.ContentLength));
            HttpFileCollection file2 = re.Files;
            HttpPostedFile file = re.Files[0];
            string aFile = file.FileName;
            string aLastName = aFile.Substring(aFile.LastIndexOf("."), (aFile.Length - aFile.LastIndexOf(".")));
            string sFileName = skey + aLastName;
            file.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory + "/uploadfile/" + sFileName);
            fhsz["status"] = 0;
            fhsz["fname"] = sFileName;

        }

        string x = fhsz.ToJson();
        HttpContext.Current.Response.Write(x);
    }
快速回复