再问!追加100分 求解

qianjing1111 2004-09-02 01:43:32
<%String prodID = request.getParameter("id");%>
.
.
.
<%
SmartUpload su = new SmartUpload();


su.initialize(pageContext);

su.upload();

//com.jspsmart.upload.File file=su.getFiles().getFile(0);

int count = su.save("/upload");

//file.saveAs("/upload"+file.getFileName());

%>
上面的程序已经能够实现图片的上传,现在我想把第一行得到的prodID值做为被上传的图片的名字,请高手指教...
...全文
131 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiking 2004-09-02
  • 打赏
  • 举报
回复
javascript 查文件名的后缀或找开源项目转文件格式!
qianjing1111 2004-09-02
  • 打赏
  • 举报
回复
因为我的prodID是唯一的,所以应该不会出现重名的现象吧?
qyzj_wanghx 2004-09-02
  • 打赏
  • 举报
回复
楼主这样做会出现问题的...重名就是例子.
qianjing1111 2004-09-02
  • 打赏
  • 举报
回复
谢谢各位 已经解决
现在进一步提问,如何限制只能上传JPG图片?
或者将上传的图片转为JPG格式?
有办法吗?
osobo 2004-09-02
  • 打赏
  • 举报
回复
给你段代码。

String picture = "", pic = "";
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();

// Initialization
mySmartUpload.initialize(config,request,response);
try {
// Upload
mySmartUpload.upload();
String servPath = request.getSession(true).getServletContext().getRealPath(request.getServletPath());
String path1 = servPath.substring(0,servPath.lastIndexOf(System.getProperty("file.separator")));
String dirPath = path1.substring(0,path1.lastIndexOf(System.getProperty("file.separator")) + 1) + "pictures" + System.getProperty("file.separator");
com.jspsmart.upload.Files files = mySmartUpload.getFiles();
com.jspsmart.upload.File myFile = files.getFile(0);
if (!myFile.isMissing()) {
pic = id + "_1" + myFile.getFileName().substring(myFile.getFileName().indexOf("."));
myFile.saveAs(dirPath + pic);
picture += pic;
for (int i = 1; i < files.getCount(); i++) {
myFile = files.getFile(i);
if (!myFile.isMissing()) {
pic = id + "_" + (i + 1) + myFile.getFileName().substring(myFile.getFileName().indexOf("."));
myFile.saveAs(dirPath + pic);
picture += "," + pic;
}
}
}
} catch (Exception e){
out.println("Unable to upload the file.<br>");
out.println("Error : " + e.toString());
yangzuyu12 2004-09-02
  • 打赏
  • 举报
回复
com.jspsmart.upload.File file=su.getFiles().getFile(0);
String name = prodID +"."+file.getFileExt();
file.saveAs("/upload/"+name);
gaochao79 2004-09-02
  • 打赏
  • 举报
回复
哇 不怕重名的?
飞翔的大麦茬 2004-09-02
  • 打赏
  • 举报
回复
SmartUpload su = new SmartUpload();
mySmartUpload.initialize(pageContext);
//文件上传
mySmartUpload.upload();
File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing()) {
myFile.saveAs( "upload/"+ prodID );
out.println("已上传文件 " + myFile.getFileName() + "<BR>");

}
lping468 2004-09-02
  • 打赏
  • 举报
回复
那你只有追加一个操作,就是用prodID重新改文件名三
bestdelphier 2004-09-02
  • 打赏
  • 举报
回复
com.jspsmart.upload.File file=su.getFiles().getFile(0);
String name = prodID +"."+file.getFileExt();
file.saveAs("/upload/"+name);

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧