andy
andy

Reputation: 55

how can I get path of file from input api

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?

Upvotes: 1

Views: 1301

Answers (2)

dfsq
dfsq

Reputation: 193261

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

Upvotes: 1

Syed Muhammad Zeeshan
Syed Muhammad Zeeshan

Reputation: 1045

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.

Upvotes: 0

Related Questions