javascript – get the filename and extension from input type=file

This is bit old post…just for info

   var files = event.target.files
   var filename = files[0].name
   var extension = files[0].type

In the type you will find the extension
for eg: if it is jpeg image then,

extension = image/jpeg

or if pdf then,

extension = application/pdf

To obtain the exact value, perform extension.replace(/(.*)\//g, ”).
you will get the value.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)