用swfupload上传,更改上传文件夹,但参数没有传递到,望帮忙!! swfuploadc#jsjqueryfunction 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DropDownList 值改变了又怎么样?你又没做处理UploadHandler.ashx始终只接收到一个request.files[0] 我这样改,但是上传的时候有错,应该怎么改啊:<script type="text/javascript"> $(document).ready(function() { var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端 var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值 $("#uploadify").uploadify({ 'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf', 'script': '#', 'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png', 'folder': typeValue, 'queueID': 'fileQueue', 'auto': false, 'multi': true, }); $('#DropDownList1').click(function () { $('#uploadify').uploadifySettings('script', 'ashx/UploadHandler.ashx?id=' + typeValue); }); }); </script>UploadHandler.ashx.cs: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\"; if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(uploadPath + file.FileName); //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write("1"); } else { context.Response.Write("0"); } } 漏了,上面的 HttpPostedFile file = context.Request.Files["Filedata"];的 Filedata 应该是 id ,怎么改?我这样改,但是上传的时候有错,应该怎么改啊:<script type="text/javascript"> $(document).ready(function() { var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端 var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值 $("#uploadify").uploadify({ 'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf', 'script': '#', 'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png', 'folder': typeValue, 'queueID': 'fileQueue', 'auto': false, 'multi': true, }); $('#DropDownList1').click(function () { $('#uploadify').uploadifySettings('script', 'ashx/UploadHandler.ashx?id=' + typeValue); }); }); </script>UploadHandler.ashx.cs: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\"; if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(uploadPath + file.FileName); //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write("1"); } else { context.Response.Write("0"); } } <script type="text/javascript"> $(document).ready(function () { $('#file_upload').uploadify({ 'auto': false, swf: 'JS/jquery.uploadify-v2.1.0/uploadify.swf', uploader: 'UploadHandler.ashx', formData: { 'folder': $('#<%=DropDownList1.ClientID %>').val() }, onUploadStart: function (file) { $('#file_upload').uploadify('settings', 'formData', { 'folder': $('#<%=DropDownList1.ClientID %>').val() }); }, onUploadSuccess: function (file, data, response) { alert(data); } }); }); </script> <form runat="server"> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> </form> <input type="file" name="file_upload" id="file_upload" /> <a href="javascript:$('#file_upload').uploadify('upload','*')">上传文件</a> context.Response.ContentType = "text/plain"; try { context.Response.Write("Folder:" + context.Request.Form["folder"] + "\rFileLength:" + context.Request.Files[0].ContentLength); } catch (Exception ex) { context.Response.Write(ex.Message); }我没用过2.1 这个是3.2的 3.2 没的folder属性但我像即使是2.1 你也应该在 onUploadStart 事件里重置 folder 的值。而不是去找$('#DropDownList1').click() 是不是DropDownList值出错了,既然用了JQ,那就用JQ的方法获取DropDownList值,$('#DropDownListID').val() 没有folder属性,也可能跟你用的浏览器有关,有些版本浏览器是去不懂folder属性,或者可以换个浏览器试试 各位,现在我知道怎么解决了,但是要解决下面的问题:就是在第29行的uploadifySettings()里面的12那里怎么引用第5行的typeValue变量? <script type="text/javascript"> $(document).ready(function() { var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端 var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值 $("#uploadify").uploadify({ 'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf', 'script': 'UploadHandler.ashx', 'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png', 'folder': 'abc', 'queueID': 'fileQueue', 'auto': false, 'multi': true, }); }); </script></head><body> <form id="form1" runat="server"> 上传到: <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <div id="fileQueue"></div> <input type="file" name="uploadify" id="uploadify" /> <p> <a href="javascript:$('#uploadify').uploadifySettings('folder','12');$('#uploadify').uploadifyUpload()">上传</a>| <a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a> </p> 其实这样就可以更改上传目录了,下面的12就是我自定义的目录:<a href="javascript:$('#uploadify').uploadifySettings('folder','12');$('#uploadify').uploadifyUpload()">上传</a>但是如果把12换成一些控件的值就不可以了,例如下面,为什么呢?<a href="javascript:$('#uploadify').uploadifySettings('folder','<%=TextBox1.Text %>');$('#uploadify').uploadifyUpload()">上传</a>| swfupload这个库已经很久没更新了,对近两年出的新版本浏览器支持较差,建议使用Plupload JQUERY 理解Application: asp.net生成静态页面的源码 菜鸟问题,高手们帮帮忙。中国人民感谢您啊~~~~ asp.net上传问题! 验证控件出错 框架的一个疑难问题。 如何检测窗口是否已经打开? 使用DataSet.Merge的问题,向了解它的各位高手求教 快疯了,但的确是个小问题啊 c# 获取JSON 转换小问题 (初学ajax..) Worksheet.SaveAs 能不能把指定的一个sheet保存成html?
UploadHandler.ashx始终只接收到一个request.files[0]
$(document).ready(function()
{
var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端
var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值
$("#uploadify").uploadify({
'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
'script': '#',
'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png',
'folder': typeValue,
'queueID': 'fileQueue',
'auto': false,
'multi': true,
});
$('#DropDownList1').click(function () {
$('#uploadify').uploadifySettings('script', 'ashx/UploadHandler.ashx?id=' + typeValue);
});
});
</script>UploadHandler.ashx.cs: public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\"; if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
$(document).ready(function()
{
var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端
var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值
$("#uploadify").uploadify({
'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
'script': '#',
'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png',
'folder': typeValue,
'queueID': 'fileQueue',
'auto': false,
'multi': true,
});
$('#DropDownList1').click(function () {
$('#uploadify').uploadifySettings('script', 'ashx/UploadHandler.ashx?id=' + typeValue);
});
});
</script>UploadHandler.ashx.cs: public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\"; if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
<script type="text/javascript">
$(document).ready(function () {
$('#file_upload').uploadify({
'auto': false,
swf: 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
uploader: 'UploadHandler.ashx',
formData: { 'folder': $('#<%=DropDownList1.ClientID %>').val() },
onUploadStart: function (file) {
$('#file_upload').uploadify('settings', 'formData', { 'folder': $('#<%=DropDownList1.ClientID %>').val() });
},
onUploadSuccess: function (file, data, response) {
alert(data);
}
});
});
</script> <form runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</form>
<input type="file" name="file_upload" id="file_upload" />
<a href="javascript:$('#file_upload').uploadify('upload','*')">上传文件</a>
context.Response.ContentType = "text/plain"; try
{
context.Response.Write("Folder:" + context.Request.Form["folder"] + "\rFileLength:" + context.Request.Files[0].ContentLength);
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
我没用过2.1 这个是3.2的 3.2 没的folder属性
但我像即使是2.1 你也应该在 onUploadStart 事件里重置 folder 的值。而不是去找$('#DropDownList1').click()
<script type="text/javascript">
$(document).ready(function()
{
var d = document.getElementById("<%=DropDownList1.ClientID %>");//根据DropDownList的客户端
var typeValue = d.options[d.selectedIndex].value;//获取DropDownList当前选中值
$("#uploadify").uploadify({
'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
'script': 'UploadHandler.ashx',
'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png',
'folder': 'abc',
'queueID': 'fileQueue',
'auto': false,
'multi': true,
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
上传到:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p>
<a href="javascript:$('#uploadify').uploadifySettings('folder','12');$('#uploadify').uploadifyUpload()">上传</a>|
<a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a>
</p>