0

我使用 uplodify 3.1 在 asp.net 中上传多个文件。它允许选择多个文件并上传它们。但我的问题是我必须为每个项目单击上传按钮。(aoto 属性设置为 false)这是我的代码:

<head>
<script src="Scripts/jquery.js" type="text/javascript"></script>
    <script src="Scripts/jquery.uploadify-3.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(window).load(
    function () {
        $("#<%=FileUpload1.ClientID%>").uploadify({
            'swf': 'Scripts/uploadify.swf',
            'uploader': 'Upload.ashx',
            'fileTypeDesc': 'Image Files',
            'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png',
            'multi': true,
            'formData': { 'galerisi': '<%=Session["galeriId"]%>' },
            'auto': false,
            'buttonImage': 'Styles/images/btnYorumEkle.png',
            'buttonText': 'Dosya seç'

        });
    }
);
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="float: left;">
            <asp:FileUpload ID="FileUpload1" runat="server" />
        </div>
        <div style="left: 136px; position: absolute; top: 18px;">
            <a class="blueButton" href="javascript:$('#<%=FileUpload1.ClientID%>').uploadify('upload')">
                Yükle</a>
        </div>
        <div style="left: 205px; position: absolute; top: 18px;">
            <a class="blueButton" href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadClearQueue()">
                Temizle</a>
        </div>
    </div>
    </form>
</body>

以及 ashx 文件中的代码:

<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.IO;

using System.Collections.Generic;
using System.Web.SessionState;
public class Upload : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{


    galeriIslemleri galeriler = new galeriIslemleri();
    Tools tollar = new Tools();


    public void ProcessRequest(HttpContext context)
    {

        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;


        try
        {
                string galeriKlasoru = context.Request["galerisi"].ToString();

                var db = Tools.DBBaglanti();
                HttpPostedFile postedFile = context.Request.Files["Filedata"];

                string savepath = "";
                string tempPath = "";
                tempPath = "images/galeriler/" + galeriKlasoru;

                savepath = context.Server.MapPath(tempPath);

                string filename = postedFile.FileName;
                if (!Directory.Exists(savepath))
                    Directory.CreateDirectory(savepath);

                postedFile.SaveAs(savepath + @"\" + filename);
                context.Response.Write(tempPath + "/" + filename);
                context.Response.StatusCode = 200;


                galeriResimleri resimler = new galeriResimleri();
                resimler.galeriId = Convert.ToInt32(galeriKlasoru);
                resimler.resim = filename;
                db.galeriResimleris.InsertOnSubmit(resimler);
                db.SubmitChanges();

        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

请帮忙。

4

1 回答 1

0

参考:http ://www.uploadify.com/documentation/uploadify/upload/

似乎如果 Auto 设置为 false,那么您必须传递星号“*”作为 fileid 才能上传队列中的所有文件。例如:

<a class="blueButton" href="javascript:$('#%=FileUpload1.ClientID%>').uploadify('upload','*')">Yükle</a>
于 2012-07-03T21:02:04.867 回答