Flash基础入门之flash上传附件
小标 2018-11-15 来源 : 阅读 1202 评论 0

摘要:本文主要向大家介绍了Flash基础入门之flash上传附件,通过具体的内容向大家展现,希望对大家学习Flash基础入门有所帮助。

本文主要向大家介绍了Flash基础入门之flash上传附件,通过具体的内容向大家展现,希望对大家学习Flash基础入门有所帮助。

//引用JS
<script src="../../../Scripts/upload/jquery.uploadify.js" type="text/javascript"></script>
    <script src="../../../Scripts/upload/jquery.uploadify.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/upload/swfobject.js" type="text/javascript"></script>
    <link href="../../../Scripts/upload/uploadify.css" rel="stylesheet" type="text/css" />

//JS方法
<script type="text/javascript">
        $(document).ready(function () {
            $("#uploadify").uploadify({
                'uploader': '/Scripts/upload/uploadify.swf',
                'script': 'Uploads.ashx',
                'scriptData': { 'lyh': '<%=Request.QueryString["lyh"] %>', 'lc': '<%=Request.QueryString["lc"] %>', 'HandlerType': 'file' },
                'method': 'Get',
                'cancelImg': '/Scripts/upload/cancel.png',
                'buttonImg': '/Scripts/upload/uploadbtn.png',
                'buttonText': '',
                'width': 120,
                'height': 28,
                'queueID': 'fileQueue',
                'auto': false,
                'multi': true,
                'queueSizeLimit': 10,
                'simUploadLimit': 1,
                'onInit': function () {
                },
                'onSelect': function (e, queueId, fileObj) {
                },
                'onComplete': function (event, queueId, fileObj, response, data) {
                    if (response == "null") {
                        $.messager.alert("系统提示", "未选择需要上传的文件。", "error");
                    } else if (response == "error") {
                        $.messager.alert("系统提示", "上传文件时发生错误。", "附件格式不对");
                    } else {
                        $.messager.alert("系统提示", "上传成功");
                    }
                }
            });
        });

        //获取附件信息
        function getAttachment() {
            $.ajax({
                type: "GET",
                dataType: "text",
                async: false,
                url: '<%=ResolveUrl("/Ajax/Common/Attachment.ashx")%>',
                data: "HandlerType=getequipment&lyh=" + '<%=Request.QueryString["lyh"] %>' + "&lc=" + '<%=Request.QueryString["lc"] %>' + "&rand=" + newCommon.atrand(10000000),
                success: function (msg) {
                    var table = "";
                    if (msg != "") {
                        table = "<table class='list' style='width:460px; margin-top:10px;margin-bottom:10px; margin-left:10px'>";
                        table += "<thead>";
                        table += "<tr style='height:28px;'>";
                        table += "<th align='left' style='border-left:1px solid #5f89c6'>&nbsp;&nbsp;楼宇号</th>";
                        table += "<th align='center' style='width:15%'>楼层</th>";
                        table += "<th align='center' style='width:15%;'>上传上传人</th>";
                        table += "<th style='width:20%;' align='center'>操作</th>";
                        table += "</tr>";
                        table += "</thead>";
                        table += "<tbody>";
                        var info = msg.split('|');
                        for (var i = 0; i < info.length; i++) {
                            var name = info[i].split(',');
                            table += "<tr style='height:28px;'><td align='left' style='border-left:1px solid #5f89c6'>&nbsp;&nbsp;" + name[1] + "</td>";
                            table += "<td align='center'>&nbsp;&nbsp;" + name[2] + "</td>";
                            table += "<td align='center'>&nbsp;&nbsp;" + name[3] + "</td>";
                            table += "<td align='center'><a class='abtn2' style='cursor:pointer; width:40px' href='/Ajax/Common/Attachment.ashx?HandlerType=download&id=" + name[0] + "' target='frm'>下载</a>";
                            table += "&nbsp;&nbsp;&nbsp;<a class='abtn2' style='cursor:pointer; width:40px' onclick='deldata(\"" + name[0] + "\")'>删除</a>";
                            table += "</td></tr>";
                        }
                        table += "</tbody>";
                        table += "</table>";
                    }
                    $("#divattachment").html(table);
                }
            });
        }

        //删除
        function deldata(attid) {
            $.messager.confirm('系统提示', '确定要删除该附件', function (r) {
                if (r) {
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        async: false,
                        url: '<%=ResolveUrl("../../../Ajax/Common/Attachment.ashx")%>',
                        data: "HandlerType=delattinfo&id=" + attid + "&rand=" + newCommon.atrand(10000000),
                        success: function (data) {
                            if (data.State == "1")
                                getAttachment();
                            else
                                $.messager.alert("系统提示", data.Message, "error");
                        }
                    });
                }
            });
        }
    </script>


//HTML代码
//显示进度条
<div style="padding: 1px;">
        <div id="fileQueue">
        </div>
    </div>
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td style="border: 0px;">
                <input type="file" name="uploadify" id="uploadify" />
            </td>
            <td style="border: 0px;">
                <a id="btnUpload" plain="true" class="easyui-linkbutton" iconcls="icon-ok" onclick=" javascript:$('#uploadify').uploadifyUpload(); ">
                    上传文件</a>
            </td>
            <td style="border: 0px;">
                <a id="btnCancle" plain="true" class="easyui-linkbutton" iconcls="icon-cancel" onclick=" javascript:$('#uploadify').uploadifyClearQueue(); ">
                    取消上传</a>
            </td>
        </tr>
    </table>
//显示附件列表
    <div id="divattachment">
    </div>



//一般处理程序代码

public override void OnRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string HandleType = context.Request["HandlerType"].ToLower();
            switch (HandleType)
            {
                case "file": //获取自定义树形结构
                    GetFIle(context);
                    break;
            }
        }

        #region 获取设备树
        /// <summary>
        /// 附件处理
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private void GetFIle(HttpContext context)
        {
            Mes oMes = new Mes();
            context.Response.ContentType = "text/plain";
            try
            {
                string basePath = Hzjg.Common.Config.ConfigManage.fGetAppConfig("SaveFilePath");
                HttpPostedFile file = context.Request.Files["FileData"];
                string extension = Path.GetExtension(file.FileName).ToUpper();
                if (extension != ".PDF" && extension != ".PNG" && extension != ".GIF" && extension != ".JPEG" && extension != ".JPG")
                {
                    context.Response.Write("格式不对");
                }
                else
                {

                    if (file != null)
                    {
                        #region 执行文件上传
                        string documentPath = @"\files\" + context.Request["lyh"] + @"\消防设备图纸\";
                        if (!Directory.Exists(basePath + documentPath))
                            Directory.CreateDirectory(basePath + documentPath);
                        if (!File.Exists(basePath + documentPath))
                        {
                            file.SaveAs(basePath + documentPath + file.FileName);
                            Model.LOGISTICS_BUILDINGEQUIPMENTPIC model = new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
                            model = cBll.GetList(" where t.LYH='" + context.Request["lyh"] + "' and t.LC='" + context.Request["lc"] + "'", "").FirstOrDefault();
                            if (model != null)
                            {
                                model.PICTUREPATH = documentPath.Replace("\\", "/") + file.FileName;
                                oMes = new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Update(model);
                            }
                            else
                            {
                                model = new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
                                model.ID = Guid.NewGuid().ToString();
                                model.LYH = context.Request["lyh"];
                                model.LC = decimal.Parse(context.Request["lc"]);
                                model.PICTUREPATH = documentPath.Replace("\\", "/") + file.FileName;
                                model.INPUTTIME = DateTime.Now;
                                model.INPUTCODE = JG.Base.Portal.AppCode.Data.CurrentUserInfo.UserCode;
                                oMes = new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Add(model);
                            }
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Hzjg.Common.Utility.Log.fWriterLog("上传发文附件异常:" + ex.Message, ex);
            }
            context.Response.Write("Succeed");
        }

        #endregion

以上就介绍了Flash的相关知识,希望对Flash有兴趣的朋友有所帮助。了解更多内容,请关注职坐标常用软件Flash频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved