control the working directory for ?
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)
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.
A quick Google search resulted in JUpload — an open source signed Java applet that seems to meet all your needs: http://jupload.sourceforge.net/
Demo site: http://jupload.sourceforge.net/advanced_js_demo.html
I’m sure there are many other such Java applets out there and it probably wouldn’t be too hard to roll your own.
The only other option I can think of is a desktop uploading application.
IE uses the last folder choosen for file uploads. If you have control over the client computers, my tips is; map a drive letter to the folder where the files are located. This can easliy be done using a cmd-file put in autoload calling subst. Then instruct the users to manually enter the drive letter, as it’s very short it should be possible to write a very clear and easy to follow instruction. Good luck.
Simply put, it is impossible to do any such thing. As you can see, all/most of the answers agree with this statement, and those that do not misunderstood the question. Sorry, but what you are trying to do is considered a security risk by most browsers.
You cannot set the value of an input file, that is a security issue.
You can use an activex control, although that stuff is getting pretty out dated. There are many advanced file upload activex controls and I bet you can pick one up pretty cheap.
Registry setting for Download directory might do the trick: (even though its an upload)
and you would have to figure out how to set it every time they open IE
HKCU\Software\Microsoft\Internet Explorer\DownloadDirectory
This works.
Here I needed to make sure the user has used input image file on the clients local image path. The UrlExists simple checks if the file could be loaded to the known path + file name.
I also needed to make the input look better than the browsers.
The trick here was placing I canvas with more work than shown here to mask the input. Setting input opacity to 0 , Here set to 0.5 so you can see the trick.
<body>
<canvas id="FancyCanvasButton" tabindex="8" width="240" height="18" style="position: absolute; left: 100px; top: 120px; border: 1px solid rgb(0, 0, 0); z-index: 1;"></canvas>
<input type="file" accept="image/*" onchange="loadFile(event)" style="opacity:0.5;position: absolute; left: 100px; top: 120px; z-index: 2; " >
<img id="output"/>
<script>
var loadFile = function(event) {
var output = document.getElementById('output');
var fName= "Images/" + event.target.files[0].name; //None path with users selected file name
if(UrlExists(fName)){
output.src=fName; //Do something like show image
}else{
alert("File not present"); // Do something to show file not in this path
}
};
function UrlExists(url) {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
if (http.status != 404){
return true;
}else{
return false;
}
}
</script>