Jquery string replace

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

How to remove this C: fakepath?

thank

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());
            }
+3
source share
5 answers

Can't you just use the string replace function?

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

You can use this and it will also remove the slashes, leaving you only the file name.

$(this).val().replace(/C:\\fakepath\\/i, '');
+6
source

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

+1

, firts beeen IE, encodeURI , , , "\". , :

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);
}

.

0

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

All Articles