大米1982 2015-07-13 08:51 采纳率: 25%
浏览 1781

mvc中使用uploadify 无法上传大文件 提示超过长度

我使用uploadify上传 修改的配置文件可是还是无法上传超过4M的文件
view代码

  <link href="~/Scripts/jquery.uploadify-v2.1.0/default.css"  rel="stylesheet" type="text/css" />
    <link href="~/Scripts/jquery.uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="~/Scripts/JQuery/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="~/Scripts/jquery.uploadify-v2.1.0/swfobject.js"></script>

    <script type="text/javascript" src="~/Scripts/jquery.uploadify-v2.1.0/jquery.uploadify.min.js"></script>

    <script type="text/javascript">
        function flashChecker() {
            var hasFlash = 0;    //是否安装了flash
            var flashVersion = 0;  //flash版本

            if (document.all) {
                var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
                if (swf) {
                    hasFlash = 1;
                    VSwf = swf.GetVariable("$version");
                    flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
                }
            } else {
                if (navigator.plugins && navigator.plugins.length > 0) {
                    var swf = navigator.plugins["Shockwave Flash"];
                    if (swf) {
                        hasFlash = 1;
                        var words = swf.description.split(" ");
                        for (var i = 0; i < words.length; ++i) {
                            if (isNaN(parseInt(words[i]))) continue;
                            flashVersion = parseInt(words[i]);
                        }
                    }
                }
            }
            return { f: hasFlash, v: flashVersion };
        }

        var fls = flashChecker();
        var s = "";
        //if (fls.f) document.write("您安装了flash,当前flash版本为: " + fls.v + ".x");
        //else document.write("您没有安装flash");
        $(document).ready(function () {
            $("#uploadFile").uploadify({
                /*注意前面需要书写path的代码*/
                'swf': '../../Scripts/jquery.uploadify-v2.1.0/uploadify.swf',
                'uploader': '/Base/uploadhandler', //请求的Action  
                'cancelImg': '../../Scripts/Scripts/jquery.uploadify-v2.1.0/cancel.png',
                'method': 'get',
                'queueID': 'fileQueue', //和存放队列的DIV的id一致   
                'fileObjName': 'uploadFile',//和input的name属性值保持一致就好,Struts2就能处理了    
                'auto': true, //是否自动开始   
                'multi': true, //是否支持多文件上传   
                'buttonText': '上传', //按钮上的文字  
                'simUploadLimit': 1, //一次同步上传的文件数目   
                'sizeLimit': 100 * 1024 * 1024, //设置单个文件大小限制                  
                //          'fileDesc'     : '支持格式:jpg/gif/jpeg/png/bmp.', //如果配置了以下的'fileExt'属性,那么这个属性是必须的   
                //          'fileExt'       : '*.jpg;*.gif;*.jpeg;*.png;*.bmp',//允许的格式     
                'queueSizeLimit': 5, //限制在一次队列中的次数(可选定几个文件)。默认值= 999,而一次可传几个文件有 simUploadLimit属性决定。  
                'fileSizeLimit': 100 * 1024 * 1024, //设置单个文件大小限制,单位为byte ,100M  
                'removeCompleted': true,
                'removeTimeout': 0.5,
                'requeueErrors': true,

                'onUploadComplete': function (file) {
                    //  $("#result").append("<div>文件"+file.name+"上传成功!</div><br/>");  
                },
                'onUploadSuccess': function (file, data, response) {
                    if ($("#hidFile").val() == "") {
                        $("#hidFile").val(data);
                        $("#showFile").text(data);
                    } else {
                        $("#hidFile").val($("#hidFile").val() + "|" + data + "");
                        $("#showFile").text($("#showFile").text() + ";" + data + "");
                    }
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString, swfuploadifyQueue) {
                    $("#result").html(errorString);  
                },
            });

        });
    </script>
</head>
<body class="easyui-layout">

    <div class="item2 mt15">
        <span class="reg-tit3">上传附件:</span>
        <div class="reg-inf">
            <input type="file" name="uploadFile" id="uploadFile" class="pub-btn" />
            <div id="fileQueue"></div>
            @*<a href="javascript:$('#uploadFile').uploadify('upload','*')">上传文件</a>
                <a href="javascript:$('#uploadFile').uploadify('cancel', '*')">取消所有上传</a>*@
        </div>
        <label id="showFile" name="showFile"></label>
    </div>
    <div class="fl ml158 mt5 f12 gray0">最多可添加5个附件,单个文件大小不得超出10M,<br>可上传文件格式:pdf、doc、docx、xls、ppt、wps、zip、rar、txt、jpg、jpeg、gif、bmp、swf、png、lsp;</div>
</body>

controller 代码


        public string UploadHandler()
        {
            HttpPostedFileBase file = Request.Files["uploadFile"];
            if (file != null)
            {
                string path = Server.MapPath("~/UploadFile");
                string pathWjj = System.DateTime.Now.ToString("yyyyMMdd");
                string root = path + "/" + pathWjj;
                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory(root);
                }
                file.SaveAs(root + "/" + file.FileName);
                return pathWjj + "/" + file.FileName;
            }
            else
            {
                return "0";
            }
        }

配置文件

 <system.web>
    <httpRuntime maxRequestLength="40960"   
    executionTimeout="6000"
    />
  </system.web>
     <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
    <security >
      <requestFiltering>
        <requestLimits maxAllowedContentLength="40960"></requestLimits>

      </requestFiltering>
    </security>

  </system.webServer>
  • 写回答

2条回答 默认 最新

  • 请叫我头头哥 2015-07-13 09:20
    关注

    你说配置文件已经改了, 还是无法上传4M以上的文件, 那你贴的这段"配置文件"的代码是改之前的还是之后的?
    如果是之后的。 那你可能还得改改, 因为maxRequestLength的单位好像不是kb,好像是byte。

    太久没做上传文件,记不清了, 你改改试试吧!

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况