我需要一个在所有浏览器中看起来几乎相同的 FileUpload,即也在 chrome 中显示文件输入字段。所以我正在使用带有此代码的自定义 FileUpload ..
CSS
<style type="text/css">
#FileUpload {
position:relative;
top: -4px;
left: 0px;
}
#BrowserVisible {
position: absolute;
top: -15px;
left: 0px;
z-index: 1;
background:url(upload.gif) 100% 0px no-repeat;
height:26px;
width:240px;
}
#FileField {
width:155px;
height:22px;
margin-right:85px;
border:solid 1px #000;
font-size:16px;
}
#BrowserHidden {
position:relative;
width:240px;
height:26px;
text-align: right;
-moz-opacity:0;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
}
</style>
Javascript
<script src="zoom/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$('.custom-upload input[type=file]').change(function () {
$(this).next().find('input').val($(this).val());
});
</script>
HTML
<div id="FileUpload">
<input type="file" size="24" id="BrowserHidden" runat="server" onchange="getElementById('FileField').value = getElementById('BrowserHidden').value;" />
<div id="BrowserVisible"><input type="text" id="FileField" runat="server" /></div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" style="height: 26px" />
</div>
使用 asp.net 服务器控制它就像
Stream fs = file_upload.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);