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

时间:2022-12-02 17:55:23

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. can someone please help me with this?

因此,一旦我从本地计算机上传文件并选中该复选框,上传的文件应移至html复选框旁边的指定位置。有人可以帮我这个吗?

1 个解决方案

#1


0  

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).

由于安全原因,您无权访问用户的文件系统。该文件只能作为用户直接交互(确认下载)的结果下载,并且只能在用户选择的目录中手动或在默认下载目录中(取决于浏览器设置)下载。

#1


0  

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).

由于安全原因,您无权访问用户的文件系统。该文件只能作为用户直接交互(确认下载)的结果下载,并且只能在用户选择的目录中手动或在默认下载目录中(取决于浏览器设置)下载。