上传文件到服务器,代码要怎么写?

爛轲 爛轲 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现代码只能上传到本地,要上传到服务器要怎么改?服务器那边要怎么接受,我用的是uploadify上传插件。
public ActionResult AppTemplateUpload()
{
Response.ContentType = "text/html";
Response.Charset = "utf-8";
HttpPostedFile file = Request.Files["Filedata"];
decimal size = Convert.ToDecimal(file.ContentLength) / (1024 * 1024);
decimal fileSize = Math.Round(size, 2);
string httpPath = "appapitest.gamersky.com" + "/";
const string upload = "UploadFiles\\AppVersionCode\\";
string uploadPath = AppDomain.CurrentDomain.BaseDirectory + upload;
string identify = DateTime.Now.ToString("yymmddhhmmss");
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + identify + file.FileName);

var UploadPath = httpPath + "Template/" + identify + file.FileName;
HttpResult hr = new HttpResult() { StatusCode = 1, Message = UploadPath, OtherParameter = fileSize.ToString() };
return new JsonResult(hr);
}
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
爛轲
.NET社区 62,272 成员 668,968 内容