文件上传限制文件类型

更新时间:2023-06-24 09:41:50 阅读: 评论: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();//表单数据
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;
}
}

本文发布于:2023-06-24 09:41:50,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1027788.html

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

标签:类型   上传   化石   电视   观后感   运动
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图