• 对js插件uploadify的一些操作


    前台JS代码

    <script>
    $(function(){
     //行程图片上传
            $(".info-r  input[type='file']").uploadify({
                formData: {
    //这里可以传一些其它参数到后台去。
                    folder: '\Upload\TravelProduct\King'  //图片保存的路径,如果没有前面//,图片就会保存到后台处理的一个路径下面去,如有保存路径为D:webUploadTravelProductKing/图片名称;如没有路径为D:/web/ExtemdClass/Upload/TravelProduct/king/图片名称
                },
                swf: '/Theme/NewBlueVacation/images/uploadify.swf',
                uploader: '/ExtendClass/UploadFiles.ashx',
                 50,
                height: 20,
                buttonText: '  ',//上传按钮文字
                buttonImage: "/Theme/NewBlueVacation/images/btn.gif",//上传按钮路径
                fileTypeExts: '*.jpg;*.png;*.gif;*.bmp',
                onUploadSuccess: function (file, data, response) {
                    var parentdiv = $(this.wrapper).parent().parent().parent();
                    var picList = parentdiv.find('.pic-list');
                    if (data == "0") {
                        $.messager.alert("提示", "上传失败!", 'error');
                    }
                    else {
                        $.messager.alert("提示", "上传成功!", 'info');
                        picList.append('<img src="' + data + '"/>');
                        var scenery = parentdiv.children("input[name='Scenery']");
                        scenery.val(scenery.val() + '|' + data);
                    }
                }
            });
    });
    前台JS代码

    后台图片处理代码

    using Common;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Web;
    
    namespace Web
    {
        /// <summary>
        /// UploadFiles 的摘要说明
        /// </summary>
        public class UploadFiles : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                HttpPostedFile file = context.Request.Files["Filedata"];
                string Dir = "Upload";
                string uploadPath = "\" + Dir + "\TravelProduct\" + DateTime.Now.ToString("yyyyMMdd") + "\";
                
                var path=context.Request.QueryString["path"];
                if(path!=null && path.ToString()!="" )
                    uploadPath = "\" + Dir + "\"+path+"\" + DateTime.Now.ToString("yyyyMMdd") + "\";
    
                if (!string.IsNullOrEmpty(context.Request["folder"]))
                {
                    uploadPath = HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\"; //从页面传过来的路径
                }
                string returnPath = uploadPath.Replace("\", "/");
                if (!string.IsNullOrEmpty(context.Request["folder"]))
                {
                    returnPath = context.Request["folder"].Replace("\", "/")+"/";
                }
                try
                {
                    uploadPath = HttpContext.Current.Server.MapPath(uploadPath);
                }
                catch (Exception e)
                { }
                if (file != null)
                {
                    if (!Directory.Exists(uploadPath))
                    {
                        Directory.CreateDirectory(uploadPath);
                    }
                    string fileType = Tool.MakeRandomNumber(8, 1) + Tool.GetPicType(file.FileName);
                    file.SaveAs(uploadPath + fileType);
                    //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                    context.Response.Write(returnPath + fileType);
                }
                else
                {
                    context.Response.Write("0");
                }
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    后台图片处理代码
  • 相关阅读:
    mysql 从5.1升级到5.5.33 后 innodb 表出错 及 innodb表修复
    (未解决)在JSTL中,session 和 sessionScope 有什么区别 ??
    ubuntu 12.04安装redis2.6.16
    SOA,不看你永远不知道的事
    Failed to retrieve procctx from ht. constr
    CUSPARSE 第三章 CUSPARAE索引和数据格式
    yii框架网址解析问题
    以图搜图相关资料
    JMeter工具的使用-ForEach
    [cocos2d-x]针对不同的设备,选取不同的自适应图片
  • 原文地址:https://www.cnblogs.com/bolanbujing/p/4349532.html
Copyright © 2020-2023  润新知