简体   繁体   中英

Download file which i have selected in html

I have a input type[file] component.After the user browses and selects a file i need to download the selected file by clicking a button.

function download(){
...
}

<input type='file' id='file1'>
<button type='button' onclick='download()'></button>

Thanks, Nawaz Ahmed

 window.onload = function() { var txt = document.getElementById('txt'); txt.value = window.onload + ''; document.getElementById('link').onclick = function(code) { this.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(txt.value); }; }; 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <div id="txtWrap"> <textarea id="txt"></textarea> </div> <a href="" id="link" download="code.txt">Download Above Code</a> 

may be you can find some idea from here , i am not sure that i am right or wrong according to your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM