我使用uplodify 3.1在asp.net上传多个文件。它允许选择多个文件并上传它们。但我的调查是我必须为每个项目点击上传按钮。 (aouto属性设置为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;
}
}
}
请帮忙。
答案 0 :(得分:0)
参考:http://www.uploadify.com/documentation/uploadify/upload/
似乎如果Auto设置为false,那么你必须传递一个星号'*'作为fileid来上传队列中的所有文件。例如:
<a class="blueButton" href="javascript:$('#%=FileUpload1.ClientID%>').uploadify('upload','*')">Yükle</a>