一、在html中:
<SCRIPT language=javascript1.2>
function showsubmenu(sid)
{
<!--
function fileChange(file) {
aspnetForm.face.src=file.value;
}
-->
</SCRIPT>
<tr bgcolor="#FFFFFF">
<td width="15%"> 圖片:</td>
<td width="85%">
<%--<asp:Image ID="img" runat="server" ImageUrl="~/ad/ad03.gif" />--%><img id="face" src="~/ad/ad03.gif" width="86"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> 圖片路徑:</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" onchange="fileChange(this)" />
<asp:Label ID="lbl" runat="server"></asp:Label></td>
</tr>
二、在代碼中:
protected void Button3_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type2 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("picture")+"\\"+name;
string fpath = Server.MapPath("upfile") + "\\" + name;
string wpath="picture\\"+name;
if (type2 == "gif" || type2 == "jpg" || type2 == "png" || type2 == "bmp")
{
FileUpload1.SaveAs(ipath);
Image1.ImageUrl = wpath;
Label1.Text = "傳送文件名爲:" + name + "<br>文件大小爲:" + size + "<br>圖片類型爲:" + type +"<br>後綴名爲"+type2+ "<br>實際路徑爲:" + ipath + "<br>虛擬路徑爲:" + wpath;
}
else
{
Image1.Visible = false;
FileUpload1.SaveAs(fpath);
Label1.Text = "傳送文件名爲:" + name + "<br>大小爲:" + size + "<br>圖片類型爲:" + type + "<br>後綴名爲" + type2 + "<br>實際路徑爲:" + fpath + "<br>虛擬路徑爲:" + wpath;
} }