前些时间做一个东西不知道怎么写下去! 网上都是先把图片上传然后再显示!
要么就是一大堆代码的那种!
其实这个还是得用<DIV></DIV>去显示图片会更好一点!
用js实现图片的比例压缩让图片一样能够很清楚!
不多话了! 贴代码!!!
页面代码主要就是JS
view plaincopy to clipboardprint?
<head runat="server">
<title>无标题页</title>
<mce:script language="javascript" type="text/javascript"><!--
function Imagesrc()
{
document.getElementById("image").src=document.all.FileUpload1.value;
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img alt="" id="image" style="height:50px;width:50px" />
<asp:FileUpload ID="FileUpload1" runat="server" οnchange="Imagesrc()" />
<br />
<asp:Button ID="btnPost" runat="server"
Text="上传" OnClick="btnPost_Click" /></div>
</form>
</body>
<head runat="server">
<title>无标题页</title>
<mce:script language="javascript" type="text/javascript"><!--
function Imagesrc()
{
document.getElementById("image").src=document.all.FileUpload1.value;
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img alt="" id="image" style="height:50px;width:50px" />
<asp:FileUpload ID="FileUpload1" runat="server" οnchange="Imagesrc()" />
<br />
<asp:Button ID="btnPost" runat="server"
Text="上传" OnClick="btnPost_Click" /></div>
</form>
</body>
defualt.aspx.cs代码
view plaincopy to clipboardprint?
protected void btnPost_Click(object sender, EventArgs e)
{
string PostName = Server.MapPath("Image");
string fileName = FileUpload1.FileName;
//是否包含此文件
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(PostName+"/"+fileName);
}
}
protected void btnPost_Click(object sender, EventArgs e)
{
string PostName = Server.MapPath("Image");
string fileName = FileUpload1.FileName;
//是否包含此文件
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(PostName+"/"+fileName);
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhoukang0916/archive/2009/08/30/4501058.aspx