ArK
ArK

Reputation: 21068

file upload problem with browser

var file_upload=document.getElementById('picture-upload').value;

The code 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

Upvotes: 1

Views: 286

Answers (1)

mwilcox
mwilcox

Reputation: 4132

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)

Upvotes: 1

Related Questions