• uploadify多文件上传实例--C#


    下载uploadify文件

    http://www.uploadify.com/

    HTML(视图)

    <html lang="zh-cn">
    <head>
        <meta content="true">
        <meta charset="UTF-8">
        <script src="~/Areas/Test/Uploadify/jquery.uploadify.js"></script>
        <link href="~/Areas/Test/Uploadify/uploadify.css" rel="stylesheet" />
        <title>uploadify多文件上传例子</title>
    </head>
    <body>
        <input type="file" id="file_upload" name="file_upload" />
    </body>
    </html>

     JS

    <script>
        $(function () {
            $('#file_upload').uploadify({
                'swf': '@Url.Content("/Areas/Test/Uploadify/uploadify-v3.1/uploadify.swf")',
                'uploader': '@Url.Action("UploadAppraisal")?resultPath=Upload',
                'auto': true,
                'fileTypeExts': '*.*',
                'fileTypeDesc':'All Files',
                'fileSizeLimit': '0',
                'buttonText': '添加文件',
                'width': 67,
                'height': 19,
                'margin-right': 0,
                multi: false,
                queueSizeLimit: 999,
                timeoutuploadLimit: 999,
                removeCompleted: true,
                uploadLimit: 999,
                'onSelect': function (file) {
    
                },
                'onUploadStart' : function(file) {
    
                },
                'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
    
                },
                'onInit': function () {
    
                },
                'onUploadSuccess': function (file, data, response) {
    
                }
            });
        });</script>

     后台(MVC控制器)

    public JsonResult UploadAppraisal(HttpPostedFileBase fileData, string resultPath)
            {
                if (fileData != null)
                {
                    try
                    {
                        // 文件上传后的保存路径
                        string filePath = Server.MapPath("../Upload/temp");
                        string Size = HumanReadableFilesize(fileData.ContentLength);
                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }
    
                        string fileNames = Path.GetFileName(fileData.FileName);// 原始文件名称
                        string fileName = Regex.Match(fileNames, @".*?(?=[.])").Value;//去掉后缀名字的文件名字
                        string fileExtension = Path.GetExtension(fileNames); // 文件扩展名
                        string saveName = Guid.NewGuid().ToString() + fileExtension; // 保存文件名称
                        string path = filePath + "\" + saveName;
                        string Filesize = HumanReadableFilesize(fileData.ContentLength);//字节大小
                        string FileDw = HumanReadableFile(fileData.ContentLength);//字节单位
                        fileData.SaveAs(path);
                      
                        return Json(new
                        { Success = true, FileName = saveName});
                    }
                    catch (Exception ex)
                    {
                        return Json(new
                        { Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                {
                    return Json(new
                    { Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet);
                }
            }

    一个页面有多个上传控件

    修改jquery.uploadify.js、jquery.uploadify.min.js

       var mydate = new Date();
            this.movieName = "SWFUpload_" + mydate.getTime().toString();

     上传大文件(Web.config)

      Web.config添加一下代码

    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <!--maxRequestLength就是文件的最大字符数,最大值不能超过2个G左右,executionTimeout是超时时间-->
        <httpRuntime targetFramework="4.5" maxRequestLength="1073741824" executionTimeout="3600" />
      </system.web>
    <system.webServer>
        <security>
          <requestFiltering>
            <!--修改服务器允许最大长度-->
            <requestLimits maxAllowedContentLength="1073741824"/>
          </requestFiltering>
        </security>
      </system.webServer>
  • 相关阅读:
    c# Array或List有个很实用的ForEach方法,可以直接传入一个方法对集合中元素操作
    js 检查字符串中是否包含中文(正则)
    Js 数组对象排序
    Js日期处理
    JS 检测字符串是否还有某个字符
    js获取URL传参
    使用JavaScript修改浏览器URL地址栏的实现代码
    上传、裁剪图片-----Jcrop图片裁剪插件
    zip拉链方法
    内置函数如help()...
  • 原文地址:https://www.cnblogs.com/zldqpm/p/10214160.html
Copyright © 2020-2023  润新知