要求:
一个页面A:有个按钮,文本框和Image
点击按钮,在按钮旁边弹出页面B
在B页面实现上传的功能,上传成功后,B页面关闭,将上传图片的相对路径传到A页面的文本框里,Image预览上传的图片
我现在主要是这样一个问题:
一个表中T有两个字段:title(图片名称),imageUrl(图片相对地址)
可以实现对这个表的添加和修改哪位有这个简单的程序
发我一份
谢谢
[email protected]

解决方案 »

  1.   


     protected void btn_upload_Click(object sender, EventArgs e)
            {
                //得到要上传的文件的全名包括路径
                string filename = this.FileUpload1.PostedFile.FileName;
                //得到要上传的文件的扩展名
                string ext = System.IO.Path.GetExtension(filename);            if (ext == ".jpg" || ext == ".JPG" || ext == ".gif" || ext == ".GIF" || ext == ".png" || ext == ".PNG")
                {
                    //判断文件的大小
                    int size = this.FileUpload1.PostedFile.ContentLength;
                    if (size > 1024 * 1024 * 2)
                    {
                        this.Response.Write("<script>alert('上传的图片不能超过两兆!');</script>");
                    }
                    else
                    {
                        //得到一个新名称
                        string newname = DateTime.Now.ToString("yyyyMMddhhmmss");
                        Random rd = new Random();
                        string sui = rd.Next(10000).ToString();
                        //真正的上传(最重要的一步)
                        this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/img/") + newname + sui + ext);
                        //  this.Response.Write("<script>alert('上传成功!');</script>");                    this.Image1.Visible = true;
                        this.Image1.ImageUrl = "../img/" + newname + sui + ext;
                    }
                }
                else
                {
                    this.Response.Write("<script>alert('只能上传图片!');</script>");
                }
            }
      

  2.   


    <asp:FileUpload ID="FileUpload1" runat="server" />
                    <asp:Button ID="btn_upload" runat="server" Text="上传" onclick="btn_upload_Click" />
      

  3.   

    window.open('','',height=500,width=550,status=1,toolbar=no,menubar=no,location=no,scrollbars=yes,top=100,resizable=yes");
    wondow.opener.document.getElementById("txt")="";
      

  4.   

    if (fileUpload.HasFile) 
            { 
                string savePath = Server.MapPath("~/upload/"); 
                if(!System.IO.Directory.Exists(savePath)) 
                { 
                    System.IO.Directory.CreateDirectory(savePath); 
                } 
                savePath = savePath + "\\" + fileUpload.FileName; 
                fileUpload.SaveAs(savePath);
            } 
      

  5.   

    经常看到有人问  
    文件上传,
    多文件上传,
    ajax上传,
    flash上传,
    jquery上传,
    ext上传,
    这里全有,看好了!
    http://www.open-open.com/ajax/Upload.htm
      

  6.   

    看这里,非常好,功能强网站
    my blog
    http://ufo-crackerx.blog.163.com/