We've used for some years a home-grown file uploader for our classic ASP website. It works like this:
- ASP page sets some specific constants and #includes an ASP library called Browse-Files.asp.
- Browse-Files.asp displays, inside the #including page, a file explorer-like view of the directories and files in a directory. It also shows various HTML links to allow file modification functions - create a directory, upload a file, move, rename and delete existing files.
- Each of these links calls a Javascript function that generates a simple HTML page in a popup window. These popups contain the required HTML form for the requested file modification activity. The HTML source for the popup pages is generated on the fly by Javascipt, rather than loading a static .htm or .asp file (this is purely so that all of the functionality of Browse-Files.asp is located in 1 file).
- The user fills in the popup form and submits. The form submits back to the parent page (form target attribute) and closes itself (Javascript timer, window.close).
- The parent page refreshes due to the form submit, showing the change the user requested.
Issue is: this has worked fine for some years on various browsers, IE 6 to 8, Firefox and Opera. However, in IE9, the file upload does not work. The other popup-based tasks such as file renaming and directory creation continue to work.
Code - the file rename popup (works in IE9 and all before):
<html>
<head>
<title>Rename</title>
<link rel="stylesheet" href="/Common/CSS/screen.css" type="text/css" media="screen" />
</head>
<body>
<h1>Rename</h1>
<p>Enter the new name for "Config Mgmt Text.txt" in the folder "General/Share-Files/":</p>
<form name="form" method="post" action="/General/Share-Files.asp" encType="multipart/form-data" target="Browse-Files" onSubmit="self.setTimeout('window.close()', 500)">
<input name="task" type="hidden" value="T03" />
<input name="path" type="hidden" value="General/Share-Files/" />
<input name="target" type="hidden" value="Config Mgmt Text.txt" />
<input name="name" type="text" tabindex="1" size="40" value="Config Mgmt Text.txt"></input>
<input name="submit" type="submit" value="Rename" tabindex="2" />
</form>
</body>
</html>
Code - the file upload popup (broken in IE9, works in all before):
<html>
<head>
<title>Add Files</title>
<link rel="stylesheet" href="/Common/CSS/screen.css" type="text/css" media="screen" />
</head>
<body>
<h1>Add Files</h1>
<p>Browse for files to add to the folder "General/Share-Files/":</p>
<form name="form" method="post" action="/General/Share-Files.asp" encType="multipart/form-data" target="Browse-Files" onSubmit="self.setTimeout('window.close()', 500)">
<input name="task" type="hidden" value="T01" />
<input name="path" type="hidden" value="General/Share-Files/" />
<input name="file1" type="file" tabindex="1" size="40"></input><br />
<input name="file2" type="file" tabindex="2" size="40"></input><br />
<input name="file3" type="file" tabindex="3" size="40"></input><br />
<input name="file4" type="file" tabindex="4" size="40"></input><br />
<input name="file5" type="file" tabindex="5" size="40"></input><br />
<input name="submit" type="submit" value="Upload Files" tabindex="6" />
</form>
<p>Note that upload speed depends on your internet connection speed.</p>
</body>
</html>
All the forms are encType="multipart/form-data"
to accomodate the file upload, and the ASP on the main page does a Request.BinaryRead(Request.TotalBytes)
first thing with the form data. It then parses the data by delimiter, splitting it out into binary data (uploaded files) and text data (regular form fields). One of these regular form fields, <input name="task" type="hidden" value="T01" />
, is how it knows what to do with the submitted data (rename a file, upload a file, etc).
So, why does uploading, and only uploading, not work in IE9?
As above, the form submit method is the same for uploading and other (working) form actions, as is the server-side parsing of HTTP POST.
Debugging has shown that the file upload popup never even submits data back to the parent page (or to itself), i.e.the form data is never submitted to the server in the first place. But, all the other forms work the same way and do submit.....
Could this be something completely unrelated to code, like an IE9 security setting?
Have even tried forcing IE8 compatability mode on IE9 (<meta http-equiv="X-UA-Compatible" content="IE=8" >
), no change.
Any assistance greatly appreciated.
Thanks
Lukas
Update:
1) "Doesn't work" means that the upload popup dissapears on submit (as it should), but nothing is ever submitted to the parent page. If I disable the auto-close on the popup: after clicking submit the text fields containing the path(s) to the file(s) to be uploaded are cleared, but nothing else happens. This suggests that it is submitting to the popup page rather than the parent page, but that doesn't really make sense, as the other (working under IE9) popup pages still correctly submit to the parent page. I'll try replacing the JS-generated popup page with a conventional ASP page that can show any HTTP POST data, and go from there.
2) If I force compatability mode on the client side (IE9 compatability view button), it does work exactly as it should. This is more workaround than fix though. I suppose it does rule out browser settings though, as compatability mode would only affect page rendering?