大侠们 给个批量上传图片的 我是学ASP.net 的 最好是用后台代码写的  
我在网上找的都不能 用   还请各位大侠们指教! 谢谢 给我个地址 就行
那位大侠 做过我 能告诉我QQ 吗??聊

解决方案 »

  1.   

    <body> 
        <form id="form1" runat="server"> 
        <div> 
        <table style="width: 343px"> 
                <tr> 
                    <td style="width: 100px"> 
                        多文件上传</td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload1" runat="server" Width="475px" /> 
                        </td> 
                    <td style="width: 100px"> 
                        </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload2" runat="server" Width="475px" /></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload3" runat="server" Width="475px" /></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="一起上传" /> 
                        <asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="448px"></asp:Label></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
            </table> 
        </div> 
        </form> 
    </body>
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page  

        protected void Page_Load(object sender, EventArgs e) 
        {     } 
        protected void bt_upload_Click(object sender, EventArgs e) 
        { 
            if (FileUpload1.PostedFile.FileName == "" && FileUpload2.PostedFile.FileName == "" && FileUpload3.PostedFile.FileName == "") 
            { 
                this.lb_info.Text = "请选择文件!"; 
            } 
            else 
            { 
                HttpFileCollection myfiles = Request.Files; 
                for (int i = 0; i < myfiles.Count; i++) 
                { 
                    HttpPostedFile mypost = myfiles[i]; 
                    try 
                    { 
                        if (mypost.ContentLength > 0) 
                        { 
                            string filepath = mypost.FileName;//C:\Documents and Settings\Administrator\My Documents\My Pictures\20022775_m.jpg 
                            string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);//20022775_m.jpg 
                            string serverpath = Server.MapPath("~/images/") + filename;//C:\Inetpub\wwwroot\WebSite2\images\20022775_m.jpg 
                            mypost.SaveAs(serverpath); 
                            this.lb_info.Text = "上传成功!"; 
                        } 
                    } 
                    catch (Exception ex) 
                    { 
                        this.lb_info.Text = "上传发生错误!原因:" + ex.Message.ToString(); 
                    } 
                } 
            } 
        } 
    }jquery 批量上传插件Uploadify
    参考
      

  2.   

    uploadify还是不错的
    http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html
      

  3.   

    http://www.open-lib.com/Type/201-1.jsp
      

  4.   

    swfupload,肯定能满足你的需求!
      

  5.   

    swfupload  具体不会用  是在网上找的源码!http://www.jb51.net/article/23225.htm   我找的这个!  但是不知道怎么把图片信息  插入数据库!!!!
      

  6.   

    swfupload上传的方法这样写,放在一个页面的pageload或者一个handler里都可以
     //保存原图和缩略图的路径
            string basePath = Server.MapPath("~");
            string savePath = @"attfiles\images\pic_news\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + @"\";
            string thumbPath = @"attfiles\_thumbs\pic_news\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + @"\";        string img_save_name = string.Empty, img_original_name = string.Empty;        //System.Drawing.Image thumbnail_image = null;
            System.Drawing.Image original_image = null;
            System.Drawing.Bitmap final_image = null;
            System.Drawing.Graphics graphic = null;        try
            {
                HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
                //上传的原始文件名和重命名的文件名
                img_original_name = Path.GetFileName(jpeg_image_upload.FileName);
                string extendname = Path.GetExtension(img_original_name).ToLower();
                img_save_name = DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0') + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + Path.GetExtension(jpeg_image_upload.FileName).ToLower();            if (!Directory.Exists(basePath + savePath))
                {
                    Directory.CreateDirectory(basePath + savePath);
                }
                if (!Directory.Exists(basePath + thumbPath))
                {
                    Directory.CreateDirectory(basePath + thumbPath);
                }
                jpeg_image_upload.SaveAs(basePath + savePath + img_save_name);            if (extendname == ".jpg" || extendname == ".png" || extendname == ".gif")
                {
                    //获取原始图
                    original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);
                    //计算宽度和高度
                    int width = original_image.Width;
                    int height = original_image.Height;
                    int target_width = 100;
                    int target_height = 100;
                    int new_width, new_height;                float target_ratio = (float)target_width / (float)target_height;
                    float image_ratio = (float)width / (float)height;                if (target_ratio > image_ratio)
                    {
                        new_height = target_height;
                        new_width = (int)Math.Floor(image_ratio * (float)target_height);
                    }
                    else
                    {
                        new_height = (int)Math.Floor((float)target_width / image_ratio);
                        new_width = target_width;
                    }                new_width = new_width > target_width ? target_width : new_width;
                    new_height = new_height > target_height ? target_height : new_height;                final_image = new System.Drawing.Bitmap(target_width, target_height);
                    graphic = System.Drawing.Graphics.FromImage(final_image);
                    graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), new System.Drawing.Rectangle(0, 0, target_width, target_height));
                    int paste_x = (target_width - new_width) / 2;
                    int paste_y = (target_height - new_height) / 2;
                    graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; /* new way */                graphic.DrawImage(original_image, paste_x, paste_y, new_width, new_height);                //保存缩略图
                    final_image.Save(basePath + thumbPath + img_save_name);
                    //显示上传图和结果
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<div style='float:left;'><img src='../attfiles/_thumbs/pic_news/");
                    sb.Append(DateTime.Now.Year.ToString());
                    sb.Append(DateTime.Now.Month.ToString().PadLeft(2, '0'));
                    sb.Append("/");
                    sb.Append(img_save_name);
                    sb.Append("' alt=''/><br/>");
                    sb.Append("<span style='color:green'>");
                    //sb.Append(img_original_name);
                    //sb.Append("重命名为");
                    sb.Append(img_save_name);
                    sb.Append("</span><div>");
                    Session["uploadedfile"] = savePath + img_save_name;
                    Response.Write(sb.ToString());
                    Response.StatusCode = 200;
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<span style='float:left;color:green;'>");
                    //sb.Append(img_original_name);
                    sb.Append("上传成功,重命名为");
                    sb.Append(img_save_name);
                    sb.Append("</span>");
                    Session["uploadedfile"] = savePath + img_save_name;
                    Response.Write(sb.ToString());
                    Response.StatusCode = 200;
                }
            }
            catch (Exception exxx)
            {
                if (File.Exists(basePath + savePath + img_save_name))
                {
                    File.Delete(basePath + savePath + img_save_name);
                }
                if (File.Exists(basePath + thumbPath + img_save_name))
                {
                    File.Delete(basePath + thumbPath + img_save_name);
                }
                Response.StatusCode = 200;
                Response.Write(img_original_name + "--<span style='color:red'>" + exxx.Message + "上传失败</span>");
            }
            finally
            {
                Response.End();
            }
      

  7.   

        <script type="text/javascript">
            var swfu;
            window.onload = function () {
                swfu = new SWFUpload({
                    upload_url: "upload.aspx",
                    post_params: {
                        "ASPSESSID": "<%=Session.SessionID %>"
                    },
                    assume_success_timeout: 0,
                    file_size_limit: "20MB",
                    file_types: "*.doc;*.xls;*.rar;*.zip;*.jpg;*.gif;*.png",
                    file_types_description: "文档",
                    file_upload_limit: "1",
                    file_queue_error_handler: fileQueueError,
                    file_dialog_complete_handler: fileDialogComplete,
                    upload_progress_handler: uploadProgress,
                    upload_error_handler: uploadError,
                    upload_success_handler: uploadSuccess,
                    upload_complete_handler: uploadComplete,
                    button_image_url: "swfupload/upload_button_small.png",
                    button_placeholder_id: "spanButtonPlaceholder",
                    button_width: 80,
                    button_height: 22,
                    button_text: '<span class="button">上传附件</span>',
                    button_text_style: '.button{font-size: 13pt;text-align:center} .buttonSmall{font-size: 10pt;}',
                    button_text_top_padding: 1,
                    button_text_left_padding: 0,
                    flash_url: "swfupload/swfupload.swf",
                    custom_settings: {
                        upload_target: "divFileProgressContainer"
                    },
                    debug: false
                });
            }
        </script>
      

  8.   

    swfupload.handler我也稍微改了点东西一并发了
    function fileQueueError(file, errorCode, message) {
        try {
            var errContent = file.name + "上传出现错误";
            if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
                errContent = "您试图同时上传的文件过多";
            }
            switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    errContent = "文件大小为0";
                    break;
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                    errContent = "文件大小超出限制";
                    break;
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                default:
                    errContent = errorCode;
                    break;
            }
            addResult(errContent);
        } catch (ex) {
            this.debug(ex);
        }
    }function fileDialogComplete(numFilesSelected, numFilesQueued) {
        try {
            if (numFilesQueued > 0) {
                this.startUpload();
            }
        } catch (ex) {
            this.debug(ex);
        }
    }function uploadProgress(file, bytesLoaded) {
        try {
            var percent = Math.ceil((bytesLoaded / file.size) * 100);
            var progress = new FileProgress(file, this.customSettings.upload_target);
            progress.setProgress(percent);
            if (percent === 100) {
                progress.setStatus("正在上传...<image src='../images/ajax-loader.gif' alt=''/>");
                progress.toggleCancel(false, this);
            } else {
                progress.setStatus("准备上传...");
                progress.toggleCancel(true, this);
            }
        } catch (ex) {
            this.debug(ex);
        }
    }function uploadSuccess(file, serverData) {
        try {
            addResult(serverData);
            var progress = new FileProgress(file, this.customSettings.upload_target);
            progress.setComplete();
            progress.setStatus(""); //操作已完成.
            progress.toggleCancel(false);
        } catch (ex) {
            this.debug(ex);
        }
    }function uploadComplete(file) {
        try {
            /*  I want the next upload to continue automatically so I'll call startUpload here */
            if (this.getStats().files_queued > 0) {
                this.startUpload();
            } else {//此处代码移至uploadSuccess
                //            var progress = new FileProgress(file, this.customSettings.upload_target);
                //            progress.setComplete();
                //            progress.setStatus("文件上传完毕.");
                //            progress.toggleCancel(false);
            }
        } catch (ex) {
            this.debug(ex);
        }
    }function uploadError(file, errorCode, message) {
        var errContent = "上传出现错误";
        var progress;
        try {
            switch (errorCode) {
                case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
                    alert("HTTP_ERROR");
                    break;
                case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
                    alert("MISSING_UPLOAD_URL");
                    break;
                case SWFUpload.UPLOAD_ERROR.IO_ERROR:
                    alert("IO_ERROR");
                    break;
                case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
                    alert("SECURITY_ERROR");
                    break;
                case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
                    alert("UPLOAD_LIMIT_EXCEEDED");
                    break;
                case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
                    alert("UPLOAD_FAILED");
                    break;
                case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
                    alert("SPECIFIED_FILE_ID_NOT_FOUND");
                    break;
                case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
                    alert("FILE_VALIDATION_FAILED");
                    break;
                case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
                    alert("FILE_CANCELLED");
                    break;
                case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
                    alert("UPLOAD_STOPPED");
                    break;
                default:
                    alert(errorCode);
                    break;
            }
            addResult(errContent);
        } catch (ex3) {
            this.debug(ex3);
        }
    }function addResult(src) {
        var newImg = document.createElement("div");
        newImg.innerHTML = src;
        //newImg.appendChild(document.createTextNode(src));
        document.getElementById("thumbnails").appendChild(newImg);
    }/* ******************************************
    * FileProgress Object
    * Control object for displaying file info
    * ****************************************** */function FileProgress(file, targetID) {
        this.fileProgressID = "divFileProgress";    this.fileProgressWrapper = document.getElementById(this.fileProgressID);
        if (!this.fileProgressWrapper) {
            this.fileProgressWrapper = document.createElement("div");
            this.fileProgressWrapper.className = "progressWrapper";
            this.fileProgressWrapper.id = this.fileProgressID;        this.fileProgressElement = document.createElement("div");
            this.fileProgressElement.className = "progressContainer";        var progressCancel = document.createElement("a");
            progressCancel.className = "progressCancel";
            progressCancel.href = "#";
            progressCancel.style.visibility = "hidden";
            progressCancel.appendChild(document.createTextNode(" "));        var progressText = document.createElement("div");
            progressText.className = "progressName";
            progressText.appendChild(document.createTextNode(file.name));        var progressBar = document.createElement("div");
            progressBar.className = "progressBarInProgress";        var progressStatus = document.createElement("div");
            progressStatus.className = "progressBarStatus";
            progressStatus.innerHTML = "&nbsp;";        this.fileProgressElement.appendChild(progressCancel);
            this.fileProgressElement.appendChild(progressText);
            this.fileProgressElement.appendChild(progressStatus);
            this.fileProgressElement.appendChild(progressBar);        this.fileProgressWrapper.appendChild(this.fileProgressElement);        document.getElementById(targetID).appendChild(this.fileProgressWrapper);
            fadeIn(this.fileProgressWrapper, 0);    } else {
            this.fileProgressElement = this.fileProgressWrapper.firstChild;
            this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
        }    this.height = this.fileProgressWrapper.offsetHeight;}
    FileProgress.prototype.setProgress = function (percentage) {
        this.fileProgressElement.className = "progressContainer green";
        this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
        this.fileProgressElement.childNodes[3].style.width = percentage + "%";
    };
    FileProgress.prototype.setComplete = function () {
        this.fileProgressElement.className = "progressContainer blue";
        this.fileProgressElement.childNodes[3].className = "progressBarComplete";
        this.fileProgressElement.childNodes[3].style.width = "";};
    FileProgress.prototype.setError = function () {
        this.fileProgressElement.className = "progressContainer red";
        this.fileProgressElement.childNodes[3].className = "progressBarError";
        this.fileProgressElement.childNodes[3].style.width = "";};
    FileProgress.prototype.setCancelled = function () {
        this.fileProgressElement.className = "progressContainer";
        this.fileProgressElement.childNodes[3].className = "progressBarError";
        this.fileProgressElement.childNodes[3].style.width = "";};
    FileProgress.prototype.setStatus = function (status) {
        this.fileProgressElement.childNodes[2].innerHTML = status;
    };FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
        this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
        if (swfuploadInstance) {
            var fileID = this.fileProgressID;
            this.fileProgressElement.childNodes[0].onclick = function () {
                swfuploadInstance.cancelUpload(fileID);
                return false;
            };
        }
    };
      

  9.   

    asp.net的fileupload控件一次只能上传一个文件,如果要上传多个,就要设置多个fileupload控件,要不就要用12楼的方法--swfupload控件了