日期:2014-05-18 浏览次数:20482 次
if(File1.PostedFile!=null) { if(File1.PostedFile.FileName.Length - File1.PostedFile.FileName.Replace(".","").Length>1) { System.Web.HttpContext.Current.Response.Write("<script>alert('你的文件有多扩展名!');</script>"); return; } if(File1.PostedFile.ContentLength>1024*1024*5) { System.Web.HttpContext.Current.Response.Write("<script>alert('你的文件大于5M了,请缩小图片大小!');</script>"); return; } string filename = string.Empty; string filename2 = File1.PostedFile.FileName; filename2 = filename2.Substring(filename2.LastIndexOf('.')); if(filename2!=".jpg" && filename2!=".gif") { System.Web.HttpContext.Current.Response.Write("<script>alert('只允许上传图片文件.gif,.jpg文件!!');</script>"); return; } char[] namechar = DateTime.Now.ToString().ToCharArray(); for (int i = 0; i < namechar.Length; i++) { if (namechar[i] != '-' && namechar[i] != ':' && namechar[i] != ' ') filename += namechar[i].ToString(); } filename += new Random().Next(100, 999).ToString(); filename += filename2; string filepath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "/" + uploadType; File1.PostedFile.SaveAs(filepath + "/" + filename); Image1.ImageUrl = "/" + uploadType + "/" + filename; }
------解决方案--------------------
图片上传如楼上所未..
视频也可以按那样的来...
不过,往往视频都很大..用这个方法不行吧...找找超级上传组件试试
------解决方案--------------------
if(File1.PostedFile!=null)
{
if(File1.PostedFile.FileName.Length - File1.PostedFile.FileName.Replace(".","").Length>1)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('你的文件有多扩展名!');</script>");
return;
}
if(File1.PostedFile.ContentLength>1024*1024*5)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('你的文件大于5M了,请缩小图片大小!');</script>");
return;
}
string filename = string.Empty;
string filename2 = File1.PostedFile.FileName;
filename2 = filename2.Substring(filename2.LastIndexOf('.'));
if(filename2!=".jpg" && filename2!=".gif")
{
System.Web.HttpContext.Current.Response.Write("<script>alert('只允许上传图片文件.gif,.jpg文件!!');</script>");
return;
}
char[] namechar = DateTime.Now.ToString().ToCharArray();
for (int i = 0; i < namechar.Length; i++)
{
if (namechar[i] != '-' && namechar[i] != ':' && namechar[i] != ' ')
filename += namechar[i].ToString();
}
filename += new Random().Ne