现在我采用上传如下<input type="file" ...在弹出的窗口中,有个文件类型,我想限制这个文件类型,比如只能上传zip包,那就在弹出的窗口中,只显示后缀名为zip的文件,其他的文件都过滤掉
这个应该比较难吧,不需要在点击upload的时候,再用js去判断,这样效果不是很好
或者用别的形式,如flash的形式,都可以,谢谢大家咯
这个应该比较难吧,不需要在点击upload的时候,再用js去判断,这样效果不是很好
或者用别的形式,如flash的形式,都可以,谢谢大家咯
调试欢乐多
import flash.net.FileReferenceList;
var fileRef:FileReferenceList = new FileReferenceList();
var allTypes:Array = [];
var 浏览类型:Object = new Object();
浏览类型.description = "浏览类型(*.mp3)";
浏览类型.extension = "*.mp3";
allTypes.push(浏览类型);
fileRef.browse(allTypes);
java多文件上传(通过commos包中的DiskFileUpload的类来重新封装请求) public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
/*
* PicForm pForm=(PicForm)form; FormFile file=pForm.getFile();
* //获取上传的绝对路径 String
* path=this.getServlet().getServletContext().getRealPath("/upload");
* //获取文件名 String
* filename=System.currentTimeMillis()+file.getFileName(); //上传的绝对路径
* String filepath=path+"/"+filename; try { FileOutputStream fos=new
* FileOutputStream(filepath); fos.write(file.getFileData());
* fos.flush(); fos.close(); System.out.println("上传成功"); } catch
* (Exception e) { // TODO: handle exception }
*/
try {
String dir = servlet.getServletContext().getRealPath("/upload");
// String path = this.getServlet().getServletContext().getRealPath(
// "/img");
DiskFileUpload dfu = new DiskFileUpload();
// 设置上传数据的最大大小为10M。
dfu.setSizeMax(0xA00000); // 设置内存缓冲区的阀值为512K。
dfu.setSizeThreshold(0x80000); // 设置临时存储文件的目录为E:\fileupload。
dfu.setRepositoryPath("E:\\fileupload"); // 得到FileItem对象的列表。
List fileItems = null; fileItems = dfu.parseRequest(request);
Iterator it = fileItems.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
String filename = new String(item.getName().getBytes(
"ISO8859-1"), "utf-8");
// System.out.println(item.getName() + item.getContentType()
// + item.getFieldName());
System.out.println(item.getContentType());
System.out.println(filename.substring(filename.lastIndexOf(".")));
String filepath = dir + "/" + filename.substring(filename.lastIndexOf("\\"));
item.write(new File(filepath));
System.out.println("success");
}
} catch (Exception e) {
e.printStackTrace();
} return null;
}
楼主参考一下,希望对你有用
flash是可以过滤后缀名的,但是我不太清楚怎么去结合还得麻烦再讲明白些