⽂件上传限制⽂件类型
public class FileUploadManager {
/** 允许上传的扩展名*/
public static String [] extensionPermit = {"txt", "xls", "zip"};
public FileUploadManager(Ur ur, HttpServletRequest request) throws Exception {
super();
ssion = Session();
运动减肥DiskFileItemFactory factory = new DiskFileItemFactory();
upload = new ServletFileUpload(factory);
三叶虫化石值钱吗SystemManager systemManager = SystemManager();
int docSize = Integer.CompanyID(), "DOCUMENT_SIZE_LIMIT").getValue());
int maxFileSize = 1024 * 1024 * docSize;
电气工程与自动化电视品牌推荐upload.tFileSizeMax(maxFileSize); // 设置单个⽂件的最⼤上传⼤⼩海蒂和爷爷电影观后感
upload.tSizeMax(maxFileSize + 500); // 设置整个request的最⼤⼤⼩
upload.tProgressListener(new FileUploadListener(request));
extensionPermit = CompanyID(), "DOCUMENT_EXT_LIMIT").getValue().split(",");//设置⽂件类型 files = upload.parRequest(request);
}
class QCServletFileUpload extends ServletFileUpload {
private Map textHash = new HashMap();//表单数据
private int fileItemCount = 0;
// 重载parRequest⽅法
public List parRequest(HttpServletRequest request) throws FileUploadException {
List items = new ArrayList();//⽂件
try {
FileItemIterator iter = getItemIterator(request);
FileItemFactory fac = getFileItemFactory();
while (iter.hasNext()) {
FileItemStream item = ();
FileItem fileItem = FieldName(), ContentType(), item.isFormField(), Name());
//OutputStream().clo();
if (fileItem.isFormField()) { // 处理form field
textHash.FieldName(), fileItem);上下一白
} el if (Name() != null && Name().length() > 0) {// 处理file field
String fileExtension = Name());
男闺密if(!sionPermit, fileExtension)){
fileItemCount++;
items.add(fileItem);
}el{
throw new FileUploadException("⽂件" + Name() + "类型不⽀持.");
}
}
}
儿童早餐吃什么
} catch (Exception e) {
e.printStackTrace();
throw new Message(), e);
}
return items;
}
}