日期:2014-05-18  浏览次数:20657 次

上传文件时怎么判断文件是否是图片
如题
我用的是smartupload

------解决方案--------------------
代码片段:

// 截取文件扩展名
String expandName = fileName.substring(fileName.lastIndexOf( ". "),fileName.length());

// 判断文件扩展名
if (!expandName.equalsIgnoreCase( ".jpg ")
&& !expandName.equalsIgnoreCase( ".jpeg ")
&& !expandName.equalsIgnoreCase( ".bmp ")
&& !expandName.equalsIgnoreCase( ".gif "))
{
arg2.getSession().setAttribute( "errormessage ", "上传头像文件扩展名仅为: .jpg .jpeg .bmp .gif! ");
return arg0.findForward( "error ");
}