0

How do I get the name of the file uploaded to a form (post) with a code similar to this:

frm.name.value  
frm.password.value
frm.email.value

How can I get the name of frm.file? I want the "synonym" of $_FILES["FILE"]["NAME"].

Need pure JavaScript code without jQuery please.

According to the HTML5 API should be frm.file.name but that doesn't works. It's returning null on the basadate.

Eltren
  • 1
  • 1
  • 1
    Keyword: HTML5 File API. – CBroe Apr 07 '14 at 18:15
  • Do you need this before the file is posted to the server, or in the response afterward? – David Apr 07 '14 at 18:15
  • You could take a look at this [previously answered question][1] [1]: http://stackoverflow.com/questions/1804745/get-the-filename-of-a-fileupload-in-a-document-through-javascript – durbnpoisn Apr 07 '14 at 18:16

1 Answers1

0
<input type="file" onchange="alert(this.value)" />

That will alert C:\fakepath\filename.extention for most browsers. You can then cut off the beginning to get just the file name.

bjb568
  • 11,089
  • 11
  • 50
  • 71