0

When i a selecting a file i need to get full path of the file like

"file:///C:/Users/prabhuvignesh/Desktop/sample.jpg" this.

is this possible by using jquery?

$("#ID").val(); gives file name and i need fill path along with all attribute like size, extension, etc..!

i need this for cordova plugin called "filetransfer" where

var win = function (r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

var fail = function (error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "text/plain";

var params = {};
params.value1 = "test";
params.value2 = "param";

options.params = params;

var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), win, fail, options);

this needs file path (fileURL), so how can i get it..? any alternate approaches are also welcome.

Vicky
  • 419
  • 2
  • 8
  • 20
  • 3
    you can not do that. browser will prevent this for security reasons. – Milind Anantwar May 12 '15 at 13:21
  • You may find this answer helpful http://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav – chxzy May 12 '15 at 13:23
  • @MilindAnantwar as i mentioned in edited part i need it for purpose and what to do in that case? – Vicky May 12 '15 at 13:29
  • @chxzy i want full path of it not only a file name as i mentioned – Vicky May 12 '15 at 13:30
  • @RajagopalPG I clearly understand your requirement, and if you have read the link above you will see it is **NOT** possible to get full file path via JavaScript for security. – chxzy May 12 '15 at 13:36

1 Answers1

2

You can only get the local name of user selected file in an HTML file input element using the File API.

For security reasons, the path is excluded from this property.

marekful
  • 13,318
  • 5
  • 30
  • 52
  • For my cordova function i need file path and for that what should i do..? – Vicky May 12 '15 at 13:30
  • Why do you need the path? File content and and some meta information is provided, you can process on server side. – marekful May 12 '15 at 13:33
  • you mean like `document.getElementById("myfileinputID").files` will be enough to get it uploaded? – Vicky May 12 '15 at 13:39
  • No. If that input is wrapped in a form with correct `enctype` attribute value and submitted to a server side script, then it will be uploaded and processing can take place in the script. – marekful May 12 '15 at 13:42