Uploadify批量上传后台传参问题

前台代码:
$("#file_upload").uploadify({
'height': 30,
'auto': false,
'queueID': 'some_file_queue',
'formData': { 'type': '' },
'swf': appPath + 'Core/Scripts/uploadify3.2.1/uploadify.swf',
'uploader': appPath + 'RecordKeepingFunction/FilesInfo/BatchUpload/FilesUpLoad.ashx',
'width': 120,
'fileSizeLimit': '4MB',
'onUploadStart': function (file) {
var type = $("select[id$=ddlType]").val();
$("#file_upload").uploadify("settings", "formData", { 'type': type });
}
});


后台代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
//获取上传文件队列
var oFile = context.Request.Files["Filedata"];
var fileType = context.Request.Form["type"];
if (oFile != null)
{
string fileName = oFile.FileName;
string filePath = DataAccess.GetParameter<string>(ParKey.CM_UPLOAD_FILE_DIR);
filePath = string.Format(@"{0}\{1}\Record Keeping Function\{2}\", filePath, DataAccess.CurrSiteCode, "TEST");

//检查路径是否存在,如果不存在,则创建文件目录
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string fileSaveName = filePath + fileName;
////保存文件至公共文件夹下
//读取上传文件的信息源
byte[] buffer = new byte[oFile.ContentLength];
Stream stream = oFile.InputStream;
stream.Read(buffer, 0, oFile.ContentLength);
//将文件上传至远程的共享目录
FileStream fs = File.Create(fileSaveName);
fs.Write(buffer, 0, buffer.Length);
fs.Close();

//添加上传文件的记录
//new RkfFileInfoManager().AddFileUploadModel(model);
// 上面的所有操作顺利完成,你就完成了一个文件的上传(和保存信息到数据库),返回成功,在此我返回1,表示上传了一个文件
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}

注意点:
'formData': { 'type': '' },一定要先初始化,然后再用赋值,这样才能在后台$("#file_upload").uploadify("settings", "formData", { 'type': type });
获取,不然在后台获取将永远是NULL值。

转载于:https://www.cnblogs.com/lookupme/p/5198099.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值