duplicate an input type file on selecting it, in an input type hidden

V. T.
V. T. used Ask the Experts™
on
Dear experts,

i have an input type file to upload something,

 <input id="formAttach" name="formAttach" class="input-file" type="file">

Open in new window


Is it possible on selecting the file, duplicate it automatically in an other input type hidden with the full path/name of the file and his extension for value in the same form ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
I don't believe any browsers today will allow you to see the client PATH.

Certain browsers might have plugins that will allow that level of access but it is a security concern.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You can get the filename like this
HTML
<input type="file" id="ff" name="myfile">

Open in new window

jQuery
$(function() {
  $('#ff').change(function() {
    var fname = this.value.split('\\').pop();
    alert(fname);
  });
});

Open in new window

The path will be c:\fakepath or similar.

As a security measure, browsers ring fence the OS so access to it is extremly limited

Author

Commented:
Hi Julian,

yep, it seems to be way but instead of get the value in a pop i would like to get it in an input type hidden with may be a getelementby(id) ?
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
HTML
<input type="hidden" name="filenameCopy" id="filenameCopy" />

Open in new window

jQuery
$(function() {
  $('#ff').change(function() {
    var fname = this.value.split('\\').pop();
    $('#filenameCopy').val(fname);
  });
});

Open in new window


As a matter of interest why do you need to do this

Author

Commented:
Thank you Slightwv for your util information.
Thank you Julian for the solution, it works well.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial