这是服务器端c#代码
protected void btnUpload_Click1(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["btnFileUpload"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
}
此代码在 Chrome 和 Mozilla 中运行良好,但在 ie 8,9 中为Request.Files["btnFileUpload"]
空。
这是html ...
<form id="form1" runat="server" enctype="multipart/form-data">
<div class="fileName">
</div>
<div id="plus" class="uploadPlusBtn">
</div>
<input type="file" id="btnFileUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click1" Text="Upload" />
</form>
以及添加的 jQuery
$(function () {
var wrapper = $('<div/>').css({ height: 0, width: 0, 'overflow': 'hidden' });
var fileInput = $('#btnFileUpload').wrap(wrapper);
$('#plus').click(function () {
fileInput.click();
});
});