当我使用文件上传时,我用来检查带有正则表达式的文件内容类型...例如
private bool IsImage(HttpPostedFile file)
{
if (file != null && Regex.IsMatch(file.ContentType, "image/\\S+") &&
file.ContentLength > 0)
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这返回我的文件是图像与否...如何检查它是一个单词(.doc/.docx)文件或不使用c#...
DOC的mimetype是:
快乐的正则表达
编辑:根据@Dan Diplo,您还应该检查.docx的MIME类型
| 归档时间: |
|
| 查看次数: |
2269 次 |
| 最近记录: |