解决方案 »

  1.   

    DropDownList 值改变了又怎么样?你又没做处理
    UploadHandler.ashx始终只接收到一个request.files[0]
      

  2.   

    我这样改,但是上传的时候有错,应该怎么改啊:<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");   
                }  
            }
      

  3.   

    漏了,上面的  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");   
                }  
            }
      

  4.   


        <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()
      

  5.   

    是不是DropDownList值出错了,既然用了JQ,那就用JQ的方法获取DropDownList值,$('#DropDownListID').val()
      

  6.   

    没有folder属性,也可能跟你用的浏览器有关,有些版本浏览器是去不懂folder属性,或者可以换个浏览器试试
      

  7.   

    各位,现在我知道怎么解决了,但是要解决下面的问题:就是在第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>
      

  8.   

    其实这样就可以更改上传目录了,下面的12就是我自定义的目录:<a href="javascript:$('#uploadify').uploadifySettings('folder','12');$('#uploadify').uploadifyUpload()">上传</a>但是如果把12换成一些控件的值就不可以了,例如下面,为什么呢?<a href="javascript:$('#uploadify').uploadifySettings('folder','<%=TextBox1.Text %>');$('#uploadify').uploadifyUpload()">上传</a>|
      

  9.   

    swfupload这个库已经很久没更新了,对近两年出的新版本浏览器支持较差,建议使用Plupload