控制<输入类型=“文件">的工作目录? [英] control the working directory for <input type="file">?

查看:22
本文介绍了控制<输入类型=“文件">的工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整故事:我正在为我的公司开展一个项目,该项目要求我们每个地点的用户上传由第三方软件生成的报告.该软件生成的所有报告始终放置在同一目录中.我们的一些不太懂计算机的员工根据过去(和正在进行的)类似艰巨任务的经验判断:将发票下载/保存到供应商网站上的特定目录,将无法找到正确的上传目录.

Full story: I am working on a project for my company that requires users at each of our locations to upload reports generated by a third party software. All reports generated by this software are always placed in the same directory. Some of our less computer-literate associates, judging by past(and ongoing) experience with a similarly difficult task: downloading/Saving invoices to a particular directory off a suppliers website, will have trouble finding the correct directory to upload from.

每个地点的计算机都运行 Windows Server 2003 并且目前有 IE6

The computers at each location are running Windows Server 2003 and currently have IE6

我们希望通过将文件输入设置为默认指向正确的目录来提高易用性和合规性.

We would like to increase the ease of use, and compliance by setting the file inputs to point to the correct directory by default.

我最初希望能够直接在输入值中设置文件,但这是有充分理由在大多数浏览器中禁用的.是否可以通过 javascript 或仅在 HTML 本身中控制用户按下浏览按钮时打开的目录?

I initially hoped to be able to set the files directly in the input values, but this is for good reasons disabled in most browers. Is it possible through javascript, or just in the HTML itself to control the directory that opens when the user presses the browse button?

如果没有,关于如何完成它还有什么其他建议?甚至像在桌面上成功设置快捷方式这样简单的方法也可以强制浏览器使用所需的工作目录.(IE 显然忽略了快捷方式的 'start in' 参数)

If not, what other suggestions on how to accomplish it? Even something as simple as a way to successfully set a shortcut on the desktop that will force the browser to use the required working directory. (IE apparently ignores the 'start in' parameter of shortcuts)

推荐答案

出于安全原因,您无法使用 JavaScript 控制文件输入的内容.否则,您可以创建一个带有文件输入字段的隐藏表单,将其设置为路径,然后使用 JavaScript 提交表单,以便在用户不知情的情况下将文件上传到您的服务器.

You cannot control the contents of a file input using JavaScript for security reasons. Otherwise, you could create a hidden form with a file input field, set it to a path, and submit the form with JavaScript in order to upload the file to your server without the user knowledge.

不幸的是,我不知道设置文件选择器默认路径的方法.如果有,我确定它将是特定于浏览器的,并且只能通过在客户端设置一些选项来使用,而不是通过 HTML 或 JavaScript.

Unfortunately, I'm not aware of a way to set the default path for the file selector. If there is one, I'm sure it will be browser-specific and can only be used by setting some option in the client side, not through HTML or JavaScript.

这篇关于控制<输入类型=“文件">的工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆