[英]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.