从xp上传文件到linux服务器下。。
上传到的文件名被改成了 xp上的路径+文件名
假如在xp系统上用与linux一样的浏览器,则没有问题, 只有一个文件名 aa.txt
如果在xp系统上用ie6上传 上传到的文件则出现 c:\aaa.txt 源文件路径加文件名从linux访问xp上的也没有出现路径加文件名的情况
上传到的文件名被改成了 xp上的路径+文件名
假如在xp系统上用与linux一样的浏览器,则没有问题, 只有一个文件名 aa.txt
如果在xp系统上用ie6上传 上传到的文件则出现 c:\aaa.txt 源文件路径加文件名从linux访问xp上的也没有出现路径加文件名的情况
截取一下文件名?就是上传到linux时 判断如果遇到c:\ 就把他截取 只要一个文件名。是这意思吗?
String path = getServletContext().getRealPath("/");
String check = request.getParameter("check");
if (ServletFileUpload.isMultipartContent(request)) {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
System.out.println("Form field" + name + "with value"
+ Streams.asString(stream) + "detected.");
} else {
String filename = new File(item.getName()).getName();
//结果如:aa.txt
//System.out.println(file.substring(file.lastIndexOf("/") + 1));
String a = filename.substring(filename.lastIndexOf("/")+1);
System.out.println("&&&&&&&&&&&&&&&&"+a);
//重新再截取一次 得到的结果还是如:aa.txt
try {
System.out
.println("File field" + name
+ "with file name" + filename
+ "detected.");
BufferedInputStream bis = new BufferedInputStream(
stream);
// if is LiNux "/"
if (check.equals("vendor")) {
path += "LICENSE/VendorPIC/";
System.out.println("**************:" + path);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(new File(path+a)));
Streams.copy(bis, bos, true);
}