简体   繁体   中英

How to upload a file to a specific location in the local machine using HTML and Javascript

I am new to javascript, one of my use case is to upload a file from my local computer to a selected directory in same computer.

HTML Code:

<!DOCTYPE html>
<html>
   <body>
      <h3>File Upload to the selected location</h3>
      <form action="">
         <input type="file" id="files" name="files[]" multiple />
         <output id="list"></output>
      </form>
      <script src="testing.js"></script>
      <br><br> Local Path (C:\Users\UserName\Documents\) <input type="checkbox" value="TestPurpose">
   </body>
</html>

JS Code:

function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object
    // files is a FileList of File objects. List some properties.
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
        output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
            f.size, ' bytes, last modified: ',
            f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
            '</li>');
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);

so once i upload a file from my local machine and select the checkbox, the uploaded file should move to the specified location besides the html checkbox. can someone please help me with this?

Due to security reasons you do not have access to user's file system. The file can only be downloaded as a result of direct interaction from user (confirming download) and only in directory selected by user either during every specific download manually or in default download directory (depends on browser settings).

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