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

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 ?
V. T.Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) 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.
Julian HansenCommented:
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
V. T.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) ?
Julian HansenCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
V. T.Author Commented:
Thank you Slightwv for your util information.
Thank you Julian for the solution, it works well.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.