1

hy users

I try to get the path of a file via html5 js

I try:

jQuery("#pfad").change(function(evt){
   var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    for (var i = 0; i < files.length; i++) {
     alert(files[i].path); 
    }

but path isn't a attribute of this file object.... what can i do?

andy
  • 55
  • 1
  • 1
  • 7

2 Answers2

1

You can't get the full file path due to security limitations. However you can read the name of the file:

jQuery("#pfad").change(function (evt) {

    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    for (var i = 0; i < files.length; i++) {
        console.log(files[i].name);
    }
});
dfsq
  • 191,768
  • 25
  • 236
  • 258
0

Most browsers dont allow to get the full file path on client side. But in case of Google Chrome and Mozilla Firefox you can get the path by:

jQuery("#pfad").change(function(evt){
    var path = $(this).val();
    alert(path);
}

I tested it on both of these browsers.