在asp.net中上传图片 [英] uploading a image in asp.net
本文介绍了在asp.net中上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在asp.net中将图像上传到本地主机服务器,然后在网页上显示.
How to upload image to local host server in asp.net and then display on the webpage.
推荐答案
您好,
您可以使用FileUpload控件上载文件,然后可以将该文件保存在服务器中. (请参见此 [此 [
Hi,
You can use FileUpload control to upload your file and then you can Save that file in the server. (See this[^])
If you want to store your file in database then you can store it in varbinary field.(See this[^])
Hope this is what you want to know.
<div>
picture
<asp:FileUpload ID="Fud_Pic" runat="server" onchange="PreviewImg(this)" />
<br />
<br />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
</div>
<div id="newPreview">
</div>
< asp button ...... ="=">
.cs_page
在按钮下,单击写此"
<asp button......="">
.cs_page
under the button click write this
if (Fud_Pic.HasFile)
{
Label1.Text = "filelength:" + Fud_Pic.FileBytes.Length
+ "<br />"
+ "filename:"
+ Fud_Pic.FileName
+ "<br />"
+ "mimetype:"
+ Fud_Pic.PostedFile.ContentType;
Fud_Pic.SaveAs(MapPath("~/images/")
+ Fud_Pic.FileName);
}
else
{
Label1.Text = "no files";
}
它工作正常...........
如果您需要弹出图片,请使用此javascript
it works fine...........
if u need a popupimage use this javascript
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
#newPreview
{
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
</style>
<script language="javascript" type="text/javascript">
function PreviewImg(imgFile)
{
var newPreview = document.getElementById("newPreview");
newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
newPreview.style.width = "80px";
newPreview.style.height = "60px";
}
</script>
</head>
这篇关于在asp.net中上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文