Reputation: 2655
I am using an input of type=file and I am trying to figure out how to extract the file location from it. I am using this code:
file = $("#uploadFiles").attr("files")[0];
var fileName = file.fileName;
var formData = 'uploadFile=' + fileName;
and when i alert formData, it says "uploadFile=temp.jpg"
What I want is the alerted message to be something like:
"uploadFile=C:\user\doug\documents\pictures\temp.jpg"
But I don't know the attribute of the file object to put in for file.fileName
Upvotes: 2
Views: 622
Reputation: 490263
Generally, you can only rely on the filename being accessible - used mainly as a preliminary extension checking (e.g. (jpe?g|png|gif)$
) on the client side (which only serves to benefit the user, to stop them from uploading a 5mb file that will be not validate on the server anyway).
You can access whatever the browser will give you with...
$('file[type=input]').val();
document.getElementById('file-input').value;
Upvotes: 3
Reputation: 887453
For security reasons, this is completely impossible in modern browsers.
Upvotes: 3