我想要实现的效果为:点击“浏览”,可以选择多张图片,然后,再通过点击“上传”按钮再提交到数据库。就是 “批量上传”功能。请行家指点指点!

解决方案 »

  1.   

    function AddFile()
    {
    var strFile="<input name=\"upload_A\" type='file' class='inputText' style='WIDTH:350px;'/><br/>";
    document.getElementById("td_uploadFile").insertAdjacentHTML("beforeEnd",strFile);
    }
    <td id="td_uploadFile" align="center">
    <input id="upload_A" name="upload_A" type="file" class="inputText"
    style="width: 350px; display:none;" runat="server" />
    </td>HttpFileCollection Files = HttpContext.Current.Request.Files;
    for (int i = 0; i < Files.Count; i++)
    {
    }
    http://topic.csdn.net/u/20100807/11/4801f6d9-4fd0-4b87-84b4-f28f9ae474d7.html
      

  2.   

    直接使用flash上传组件上传.
    swfupload
    http://www.swfupload.org/
      

  3.   

    protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                
                fileup(FileUpload6, TextBox1);
                fileup(FileUpload5, TextBox2);
                fileup(FileUpload4, TextBox3);
                fileup(FileUpload3, TextBox4);
                fileup(FileUpload2, TextBox5);         
                  
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool fileup(FileUpload f,TextBox tex)
        {
            Boolean bo = false;
            string magazine_id = DropDownList1.SelectedItem.Value;
            string image_re = tex.Text;
            string time = System.DateTime.Now.ToString();
            if (f.HasFile)
            {
                String name = f.PostedFile.FileName;
                FileInfo file = new FileInfo(name);
                //string fileName = file.Name;
                string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + file.Name; ;            string webFilepath = Server.MapPath("userfiles/IMAGE/myphoto/" + magazine_id + fileName);
                string fileContentType = f.PostedFile.ContentType;            if (fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/jpg")
                {
                    if (!File.Exists(webFilepath))
                    {
                        try
                        {
                                                   
                            f.SaveAs(webFilepath);                        this.AddImageWater(webFilepath);                        string url = "~/userfiles/IMAGE/myphoto/" + magazine_id + fileName;
                            
                            string sql2 = "insert into image(image_url,image_re,magazine_id)values('" + url + "','" + image_re + "','" + magazine_id + "')";
                            Datacommand.datacom().exqut(sql2);
                            Response.Write("<script language = javascript>alert('提交成功!');</script>");
                            
                                                    bo = true;
                        }
                        catch (Exception ex)
                        {
                            Label9.Visible = true;
                            Label9.Text = "图片上传失败,失败原因:" + ex.Message;
                        }
                    }
                    else
                    {
                        Label9.Visible = true;
                        Label9.Text = "图片已存在,请重命名后上传";                }
                }
                else
                {
                    Label9.Visible = true;
                    Label9.Text = "为节省服务器空间,提高网站速度,请上传*.jpg、*.gif、*pjpeg类型图片";
                }            
            }
            return bo;
        }