2

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

2 Answers 2

3

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...

jQuery

$('file[type=input]').val();

JavaScript

document.getElementById('file-input').value;
Sign up to request clarification or add additional context in comments.

Comments

3

For security reasons, this is completely impossible in modern browsers.

1 Comment

unless you're working on a local script, in which case it is possible on some browsers (at least Firefox) to request additional permissions, such as File IO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.