<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ include file="checkbbsuser.jsp"%>
<%@ include file="../inc/conn.jsp"%>
<%//@ include file="../inc/ftbbstohtml.jsp"%>
<%
    String strsql,userimg;;
    Date currTime = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.US);
    String ftime=new String(formatter.format(currTime).getBytes("iso-8859-1"));
	
    SimpleDateFormat formatter2 = new SimpleDateFormat("yyyyMMddhhmmss",Locale.US);
    String ptime=new String(formatter2.format(currTime).getBytes("iso-8859-1"));

SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();

com.jspsmart.upload.File file = su.getFiles().getFile(0);
if (!file.isMissing()){
String myFileName=file.getFileName();//取得上载的文件的文件名
String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));//取得不带后缀的文件名

int fileSize=file.getSize();//取得文件的大小
String  ext= su.getFiles().getFile(0).getFileExt(); //取得后缀名
if(fileSize>100000)
{
   out.print("<script language='javascript'>");
   out.print("alert('你上传文件太大了！');");
   out.print("history.go(-1);");
   out.print("</script>");
   out.close();
   return;
}
if (ext.equals("gif")||ext.equals("GIF")||ext.equals("jpg")||ext.equals("JPG"))
{
}
else
{
   out.print("<script language='javascript'>");
   out.print("alert('只能上传gif,jpg文件类型！');");
   out.print("history.go(-1);");
   out.print("</script>");
   out.close();
   return;
}
String picname=ptime+"."+ext;
userimg = picname;

file.saveAs("/bbs/userheadimg/"+picname);//将文件保存在服务器端
}
else{
userimg = "";
}

if(userimg==null||userimg.equals("")){ 
    
}
else{
strsql="update clubuser set userimg='"+userimg+"' where clubuser_name='"+session.getAttribute("name")+"'";
stmt.executeUpdate(strsql);
}
response.sendRedirect("userimg.jsp");
%>