简体   繁体   English

如何使用HTML和Javascript将文件上传到本地计算机中的特定位置

[英]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. 我是javascript新手,我的用例之一是将文件从本地计算机上载到同一计算机中的选定目录。

HTML Code: HTML代码:

<!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: JS代码:

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. 因此,一旦我从本地计算机上载文件并选中该复选框,上载的文件应移到html复选框之外的指定位置。 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). 该文件只能作为与用户直接交互(确认下载)的结果而下载,并且只能在每次手动下载过程中或在默认下载目录(取决于浏览器设置)中用户选择的目录中下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 JS API 将文件上传到 Google 云端硬盘中的特定位置? - How to upload a file into a specific location in the Google Drive using the JS API? 使用JavaScript / Jquery将文本文件下载/更新创建到本地客户端计算机中的特定位置 - Create text file download/update into a particular location in local client machine using JavaScript/Jquery 从本地计算机上的本地计算机上载文件 - file upload from local machine on local machine 使用本地计算机上的js / html文件读取本地文本文件 - Read local text file using js/html file on on local machine 如何在特定位置存储或上传音频文件? - How to store or upload audio file in specific location? 如何使用javascript在服务器上上传本地word docx文件 - How to Upload a local word docx file on server using javascript 使用javascript,xhtml或Flash从客户端计算机上的特定文件夹上载文件? - javascript, xhtml, or flash to upload a file FROM a specific folder on a client machine? 如何使用javascript或jquery在磁盘上的特定位置下载文件? - how to download a file on disk with specific location using javascript or jquery? Javascript读取本地/(与html相同的机器)xml文件 - Javascript reading local/(same machine as the html) xml file Javascript:如何将文件位置保存到本地存储? - Javascript: How to save file location to local storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM