0

Can you please take a look at this demo and let me know why I am not able to get the name of the file(image)

$('input:file').on('change', function(){
  console.log($(this).prop("files")['name']);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <input type="file" name="file" id="test" />

As you can see I am getting undefined in console.

1 Answer 1

3

$(this).prop("files") returns a FileList, not a single file.

You'd need to do:

$(this).prop("files")[0]['name']

See: https://developer.mozilla.org/en-US/docs/Web/API/FileList

Sign up to request clarification or add additional context in comments.

Comments

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.