【发布时间】:2015-08-08 20:41:02
【问题描述】:
ASP.NET MVC中如何获取上传图片的尺寸?
这是我的FileHelper类上传文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Mvc;
namespace workflow.helpers
{
public class FileHelper
{
private HttpPostedFileBase file {get; set;}
public bool ValidFile { get; set;}
public FileHelper(HttpPostedFileBase File, string Extensions, int MaxSize=1, bool IsImage = true, string Dimensions="")
{
this.file = File;
validateFile(Extensions, MaxSize, IsImage, Dimensions);
}
public string uploadFile()
{
if (this.file.ContentLength > 0)
{
if (this.ValidFile)
{
var fileName = Path.GetFileName(this.file.FileName);
var path = Path.Combine(HttpContext.Current.Server.MapPath("~/sharedfiles/uploads/images"), fileName);
this.file.SaveAs(path);
return this.file.FileName;
}
else return "invalid file";
}
return "";
}
private void validateFile(string extensions, int MaxSize, bool IsImage = true, string Dimensions )
{
if (extensions.Contains(Path.GetExtension(this.file.FileName).Replace(".", "")))
{
if ((((double)(file.ContentLength) / 1024) / 1024) < MaxSize)
this.ValidFile = true;
}
else
this.ValidFile = false;
}
}
}
但是我仍然不知道是否可以在此类中检查上传图像的尺寸。
【问题讨论】:
-
如果链接的副本不够,请考虑搜索您帖子的标题,以澄清为什么您的问题尚未在 SO 上得到回答:bing.com/…
标签: c# asp.net asp.net-mvc asp.net-mvc-4