【发布时间】:2014-11-10 19:19:10
【问题描述】:
我只想知道发布的文件扩展名类型,
public static void UploadFile(HttpPostedFile file)
{
....
if (file != null && file.ContentLength > 0)
{
string fileName = file.FileName;
string contentType = file.ContentType;
file.SaveAs(path);
}
}
上面的代码给了我们contentType
但是如果我们手动更改扩展名,例如如果我将 untitled.exe 更改为 untitled.txt contentType 将变为文本。但我想知道它是一个exe。
有可能吗? 或者其他方式是安全的? (我认为没有)
【问题讨论】:
-
你怎么不能用
InsdexOf(".") -
如果
fileName有完整的文件路径,只需使用以下string ext = System.IO.Path.GetExtension(fileName);
标签: c# asp.net file file-upload file-extension