首页新闻找找看学习计划

.net webform 图片上传与显示

0
悬赏园豆:50 [已解决问题] 解决于 2015-03-24 21:26

我想在页面中实现点击上传本地图片,并且在网页中显示,求大神指点

问题补充:

上传的文件出现在指定的路径

蓝小天的主页 蓝小天 | 初学一级 | 园豆:33
提问于:2015-03-22 23:29
< >
分享
最佳答案
0

看看这个吧,很简单:

http://www.cnblogs.com/chenkai/archive/2013/01/04/2844702.html

收获园豆:50
XiaoFaye | 老鸟四级 |园豆:3082 | 2015-03-23 08:42
其他回答(2)
0

获取路径呀,一个input标签,一个file类型,一个javascript获取,然后传值

预览代码:

<script language=JavaScript>
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 120/80){
if(image.width>120){
ImgD.width=120;
ImgD.height=(image.height*120)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>80){
ImgD.height=80;
ImgD.width=(image.width*80)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
/**//*else{
ImgD.src="";
ImgD.alt=""
}*/
}

function FileChange(Value){
flag=false;
document.all.uploadimage.width=10;
document.all.uploadimage.height=10;
document.all.uploadimage.alt="";
document.all.uploadimage.src=Value;
}

function BeforeUpLoad(){
if(flag) alert("OK");else alert("FAIL");
}
</script>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage height=10 width=10 src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button>

_Vegetables | 园豆:569 (小虾三级) | 2015-03-23 08:55
0

在Winform里添加:

上传图片:
            <asp:FileUpload ID="fileUploadImage" runat="server" CssClass="file_upload_300" />
            图片名:
            <asp:Button ID="btnUpload" runat="server" Text="上传" CssClass="btn"
                onclick="btnUpload_Click" ToolTip="只接受JPG文件,单张大小不超过2M" />
       <asp:Label ID="lblMsg" runat="server" Text="" CssClass="msg_error"></asp:Label>
        <asp:Image ID="Image1" runat="server" />

后台:

protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            lblMsg.Text = "";
            savePicture("imgpic");
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
// 保存图片
    protected void savePicture(string name)
    {
        if (!fileUploadImage.HasFile)
        {
            lblMsg.Text = "请选择文件!";
            return;
        }

        string filepath = "", fileExtName = "", mFileName, mPath;

        filepath = fileUploadImage.PostedFile.FileName;
        fileExtName = filepath.Substring(filepath.LastIndexOf(".") + 1);
        if (fileExtName.ToLower() != "jpg" && fileExtName.ToLower() != "jpeg")
        {
            lblMsg.Text = "请选择JPG文件!";
            return;
        }
        mPath = Server.MapPath("img\\");
        mFileName = name + ".jpg";
        fileUploadImage.PostedFile.SaveAs(mPath + mFileName);
    Image1.ImageUrl = "img/" + mFileName;
}

 

酱油能 | 园豆:386 (菜鸟二级) | 2015-03-23 10:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册