上传文件到服务器,代码要怎么写?
爛轲 2016-01-18 05:32:01 现代码只能上传到本地,要上传到服务器要怎么改?服务器那边要怎么接受,我用的是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);
}