且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

控制<输入类型=“文件">的工作目录?

更新时间:2022-11-30 10:44:55

出于安全原因,您无法使用 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.