3

need help on this, trying to upload images from IE9 I get an C:fakepath/name_of_my_file

how do I remove this C:fakepath?

Thanks

if($('#ficheiro').val().search(/C:fakepath/)) {
                $('#ficheiro').val().val($('#ficheiro').val().replace('C:fakepath',''));
                nome.val('pics/'+$('#ficheiro').val());
            } else {
                nome.val('pics/'+$('#ficheiro').val());
            }

5 Answers 5

6

You can use this and it will also remove the slashes leaving you just the filename.

$(this).val().replace(/C:\\fakepath\\/i, '');
Sign up to request clarification or add additional context in comments.

Comments

5

Can't you simply use the replace function of string?

nome.val("pics/" + $('#ficheiro').val().replace("C:fakepath", ""));

1 Comment

if(ficheiro.search(/C:fakepath/)) { ficheiro = ficheiro.replace('C:fakepath',''); nome.val(dominio+'/pics/'+ficheiro); } else { nome.val(dominio+'/pics/'+ficheiro); }
1

var path = new String($('#ficheiro').val());
path = path.replace("C:fakepath", "");

Comments

0

Have a solution for you, firts check for browser beeen IE, next use encodeURI to encode all the file path and name, you have to do that first in order to capture correctly the unscaped chars like "\". Then just replace, its working for me:

var browserName=navigator.appName; 
if (browserName=="Microsoft Internet Explorer")
{
    var soloNombre = encodeURI(soloNombre);
    soloNombre = soloNombre.replace("C:%5Cfakepath%5C","");
    var soloNombre = decodeURI(soloNombre);
    alert(soloNombre);
}

Works like a charm.

1 Comment

whilst we appreciate your efforts on Stack Overflow can you be careful with copy and paste boilerplate answers as these tend to be get flagged for "spammyness". Try and tailor your answers to the OP's specific problem and code example. Thanks.
0

Try this

$(function() {
     $("input:file").change(function (){
       var fileName = $(this).val().replace("C:\\fakepath\\", "");
     });
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.