response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
SmartUpload mySmartUpload = new SmartUpload();
String currentDirectoryPath=null;
String savePath="E:/public_html/java_root/NETDISK/WebRoot/NET_SPACE/1/我的音樂/";
//mySmartUpload.setDenyPhysicalPath(true);
mySmartUpload.setForcePhysicalPath(true);
mySmartUpload.initialize(this.getServletConfig(), request,response);
// 設定上傳限制
// 1.限制每個上傳文件的最大長度。10M
mySmartUpload.setMaxFileSize(10000000); // 2.限制總上傳數據的長度。
// mySmartUpload.setTotalMaxFileSize(20000);
// 3.設定允許上傳的文件(通過擴展名限制),僅允許doc,txt文件。
// mySmartUpload.setAllowedFilesList("doc,txt");
// 4.設定禁止上傳的文件(通過擴展名限制),禁止上傳帶有exe,bat, jsp,htm,html擴展名的文件和沒有擴展名的文件。
// mySmartUpload.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// Deny physical path
try {
mySmartUpload.upload();
} catch (SmartUploadException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//讀取其它數據
com.jspsmart.upload.Request req = mySmartUpload.getRequest();
String title = req.getParameter("dest");
//保存文件
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);
if (file.isMissing()) continue;
try {
file.saveAs(savePath+file.getFileName());
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.info("e:"+e);
}
}
out.println("dest:"+title);
out.close();