急。。我为什么总是不能命名上传的文件名

wangkunhong 2004-09-20 04:37:55
<%
try{
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.setMaxFileSize(200000000);
su.setTotalMaxFileSize(20000000);
su.setAllowedFilesList("jpg,gif,bmp,png,ico");
su.setDeniedFilesList("exe,bat,jsp,htm,html,asp,");
su.upload();
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if (file.isMissing()) continue;
java.util.Date date = new java.util.Date();
String datetime = new Timestamp(date.getTime()).toString();
String image = date.getTime() + "." +file.getFileExt();
su.save("/myrc/Office/upload/" + image);
String Sql = "update per set image = '"+ image +"' where " +
"regname = '"+session.getAttribute("loginuser")+"'";
stmt.execute(Sql);
stmt.close();
}
response.sendRedirect("JobPhoto.jsp");
}catch (Exception e){
out.println(e.getMessage());
}
%>
su.save("/myrc/Office/upload/");这样就可以上传,但是文件名是原来的。。
su.save("/myrc/Office/upload/" + image);这样就不行了,郁闷啊。。
...全文
74 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
snowman_pc 2004-10-03
你得用SAVEAS吧!
回复
wangkunhong 2004-09-20
搞定了,呵呵~~
回复
wangkunhong 2004-09-20
怎么我总是遇到怪事啊
回复
wangkunhong 2004-09-20
但是我的用saveAs出错,This path does not exist (1135).这个错误应该是找不到路径吧,但是如果我不重命名文件的话,又可以传到这个文件夹中。。。是咋回事。。。
回复
qukmei 2004-09-20
一般都是用saveAs的
回复
wangkunhong 2004-09-20
我的image取值有取到1095672233171.jpg
报错为:This path does not exist (1135).
权限也有啊,我不改名都传上去过。。
回复
wangkunhong 2004-09-20
为什么你们都是myFile.saveAs,而我的组件则是.save啊,没有As,加了出错,郁闷。。
回复
zyb1235 2004-09-20
try {

// Variables
int count=0;
mySmartUpload.setAllowedFilesList("gif,jpg");

// Initialization
mySmartUpload.initialize(pageContext);

mySmartUpload.setTotalMaxFileSize(200000);

// Upload
mySmartUpload.upload();
com.java.zyb.upload.SmartFile myFile = mySmartUpload.getFiles().getFile(0);
com.java.zyb.upload.SmartFiles files=mySmartUpload.getFiles();
com.java.zyb.upload.SmartFile file=files.getFile(0);
String filename=file.getFileName();
String filePath=file.getFilePathName();
String mingcheng=DateUtils.formatDateString8() + "."+ file.getFileExt().toLowerCase();
path = path + "//" + mingcheng;
// out.println(filePath);
// if(1==1) return;



// Save the files with their original names in the virtual path "/upload"
// if it doesn't exist try to save in the physical path "/upload"
//count = mySmartUpload.save(path);
myFile.saveAs(path, SmartUpload.SAVE_PHYSICAL);
// out.println(count);
// if(1==1) return;

// Save the files with their original names in the virtual path "/upload"
// count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL);

// Display the number of files uploaded
out.println("<script language=JavaScript>");
out.println("alert('图片上传成功');");
//out.println("window.parent.parent.frm.pic.value='"+filename+"';");
out.println("history.go(-1);");
//out.println("window.close();");
//out.println("window.opener.frm.picAddress.value='"+filename+"';");

//out.println("window.opener.close();");
out.println("</script>");

} catch (Exception e) {
// out.println(e.toString());
out.println("<script language=JavaScript>");
out.println("alert('图片上传错误,要求gif,jpg文件或者文件不超过200k"+path+"');");
// out.println("window.close();");

out.println("history.go(-1);");
//response.redirect("uploadpic.htm");
out.println("</script>");

}



DateUtils.formatDateString8()时间变量生成的20040920
path的原始值是路径
回复
wangkunhong 2004-09-20
up
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-20 04:37
社区公告
暂无公告