gpt4 book ai didi

c# - 获取上传图像的尺寸?

转载 作者:太空狗 更新时间:2023-10-30 00:14:12 26 4
gpt4 key购买 nike

<分区>

如何在 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;
}
}
}

但我仍然不知道是否可以在此类中检查上传图片的尺寸。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com