这个是.aspx页面中用来上传文件的接口,适用于App接口
int maxlength = * * ;//3M
picPath = Server.MapPath(".........");
HttpFileCollection postfile = Context.Request.Files;
for (int i = ; i < postfile.Count; i++)
{
HttpPostedFile file = postfile[i];
if (!CheckType(GetExtension(file.FileName).Substring()))
{
r.success = false;
r.message = "文件类型不正确,上传失败!";
}
if (file.ContentLength > maxlength)
{
r.success = false;
r.message = "上传文件的大小超过了3MB的最大容量!请压缩后再上传!";
}
string strNewPath = DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + DateTime.Now.Millisecond + GetExtension(file.FileName);
file.SaveAs(picPath +"/"+ strNewPath);
strNewPath = strNewPath.Replace("\\", "/");
urlPath = picServer + strNewPath;
originalname = GetOriginalName(file.FileName);
if (originalname == "")
{
originalname = file.FileName;
}
string newName = GetOriginalName1(strNewPath);
file.SaveAs(Server.MapPath(".") + "/" + Path.GetFileName(file.FileName));
}