asp.net MVC 上传图片 获取图片的大小及尺寸
以下代码已经可以上传,但是我不会在上传前判断上传的文件是不是超过了规定的大小(20K-200K)及尺寸(352*288).
麻烦大牛们指点一下.注意 是MVC的模式上传
本人的100%结贴率,而且结束速度很快.先谢过
C# code:
<input type="file" id="fileImage" name="fileImage" />
<input type="submit" value="Upload" />
public ActionResult Index()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection collection)
{
if (Request.Files.Count == 0)
{
return View();
}
var c = Request.Files[0];
if (c != null && c.ContentLength > 0)
{
int lastSlashIndex = c.FileName.LastIndexOf("\\");
string fileName = c.FileName.Substring(lastSlashIndex + 1, c.FileName.Length - lastSlashIndex - 1);
fileName = Path.Combine(CommonUtility.DocImagePath, fileName);
c.SaveAs(fileName);
}
return View();
}
UP
谢谢UP,也沉的忒快了
客户端能解决就客户端JS做
那是客户端
相关问答:
服务器现在是。net 2.0的
我现在的项目就是asp.net mvc + linq的,现在服务器的环境配置用不了。
不知道有前辈碰到过这样的问题没。
难道服务器必须要装.net3.5 和 asp.net mvc
请前辈指点
不装你认为你要怎么 ......
静态模板:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/ ......
3个radioButton
一个Button
一个label
C# code:
protected void Button1_Click(object sender, EventArgs e)
{
string str = null;
RadioButton rdo=(RadioButton)sender;
......