file upload problem with browser
var file_upload=document.getElementById('picture-upload').value;
The co开发者_运维百科de returns diffrent values in two browsers.
in firefox,ie returns 'filename.ext' example: test.jpg
but in opera returns 'fullpath\filename.ext example:C:\fake_path\test.jpg
Is any one knows the problem
IE6 will also give you a full path, while newer browsers only give the file name. It's for security.
I would check for back or forward slashes in the name and if the exist, strip off the path.
if(/\\/.test(value)){
value = value.split("\")[value.split("\").length-1];
}else
if(/\//.test(value)){
value = value.split("/")[value.split("/").length-1];
}
(that code could probably be tightened up)
精彩评论