package com.test.upload;
import org.apache.commons.fileupload.*;
import org.apache.commons.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
public class Upload {
HttpServletRequest request;
String dir="";
public Upload(HttpServletRequest request)
{
this.request=request;
dir=request.getRealPath("");
}
public void upload() throws Exception
{
DiskFileUpload dfu=new DiskFileUpload();
List fileItems=dfu.parseRequest(request,4096,4194304,dir+"//test");
Iterator it=fileItems.iterator();
while(it.hasNext())
{
FileItem f=(FileItem)it.next();
String key="";
if(f.isFormField())
{
key=f.getFieldName();
}
else
{
String fileName=f.getName();
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd");
String d=sdf.format(date);
if(fileName!=null)
{
f.write(new File(dir+"//test//"+d+".jpg"));
}
}
}//while
}
}