开发者

file upload problem with browser

开发者 https://www.devze.com 2023-01-04 03:30 出处:网络
var file_upload=document.getElementById(\'picture-upload\').value; The co开发者_运维百科de returns diffrent values in two browsers.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消