Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - control the working directory for <input type="file">?

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.

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.

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?

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...