文件上传限制文件类型

更新时间:2023-07-14 23:13:20 阅读: 评论:0

⽂件上传限制⽂件类型
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();//表单数据
bakenprivate int fileItemCount = 0;
// 重载parRequest⽅法
public List parRequest(HttpServletRequest request) throws FileUploadException {
releaList 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{cph girls
throw new FileUploadException("⽂件" + Name() + "类型不⽀持.");
}自强英语
}
}
形容词的比较级和最高级
} catch (Exception e) {
e.printStackTrace();
throw new Message(), e);
}
return items;define
}
}

本文发布于:2023-07-14 23:13:20,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/177587.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:类型   上传   表单   环球   轻放   比较级
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图