public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string msg = "";

            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();
            B_WaterConfig      bc    = new B_WaterConfig();
            WaterConfig        mx    = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         name = "icon";
                string         savepath = GetPath();
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                name          = name + fileExtension;
                string ServerPath = System.Web.HttpContext.Current.Server.MapPath("/");
                string fdir  = ServerPath + savepath + "/icon" + fileExtension;
                string fdirs = ServerPath + savepath + "/icon_small" + fileExtension;
                if (File.Exists(fdir))
                {
                    File.Delete(fdir);
                }
                if (File.Exists(fdirs))
                {
                    File.Delete(fdirs);
                }
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }

                string OldImage = savepath + name;
                //生成所有自定义规格
                ImageHelper.UPLoad(OldImage, savepath, "icon_small" + fileExtension, 100, 100, "Cut");

                //写入数据库
                Lebi_Image model = new Lebi_Image();
                model.Image     = name;
                model.Keyid     = 0;
                model.Size      = "100,100";
                model.TableName = "temp";
                B_Lebi_Image.Add(model);
                msg = "OK";
                Response.Write("{\"msg\":\"" + msg + "\",\"ImageUrl\":\"" + model.Image + "\"}");
                return;
            }
            msg = Language.Tag("没有选择任何文件", "");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
Exemple #2
0
        private void showpic(System.Drawing.Image image, string exname)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            System.Drawing.Imaging.ImageFormat t = System.Drawing.Imaging.ImageFormat.Jpeg;
            if (exname.ToLower() == ".gif")
            {
                t = System.Drawing.Imaging.ImageFormat.Gif;
            }
            if (exname.ToLower() == ".png")
            {
                t = System.Drawing.Imaging.ImageFormat.Png;
            }
            if (image.Width > 300)
            {
                B_WaterConfig bc = new B_WaterConfig();
                WaterConfig   mx = bc.LoadConfig();
                if (mx.OnAndOff == "1")
                {
                    image = ImageHelper.MakeWater(image, mx);
                }
            }
            image.Save(ms, t);
            Response.ClearContent();
            Response.ContentType = "image/jpeg";
            Response.BinaryWrite(ms.ToArray());
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!EX_Admin.Power("watermark_edit", "水印设置"))
            {
                PageReturnMsg = PageNoPowerMsg();
            }

            B_WaterConfig bconfig = new B_WaterConfig();

            model = bconfig.LoadConfig();
        }
Exemple #4
0
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            //Response.ContentType = "text/plain";
            //Response.Charset = "utf-8";

            System.Drawing.Bitmap   bitmap   = null;                 //按截图区域生成Bitmap
            System.Drawing.Image    thumbImg = null;                 //被截图
            System.Drawing.Graphics gps      = null;                 //存绘图对象
            System.Drawing.Image    finalImg = null;                 //最终图片
            string pointX = RequestTool.RequestSafeString("pointX"); //X坐标
            string pointY = RequestTool.RequestSafeString("pointY"); //Y坐标
            string imgUrl = RequestTool.RequestSafeString("imgUrl"); //被截图图片地址
            string rlSize = "80";                                    // context.Request.Params["maxVal"];        //截图矩形的大小

            int           finalWidth  = 80;
            int           finalHeight = 80;
            BaseConfig    conf        = ShopCache.GetBaseConfig();
            B_WaterConfig bc          = new B_WaterConfig();

            if (!string.IsNullOrEmpty(pointX) && !string.IsNullOrEmpty(pointY) && !string.IsNullOrEmpty(imgUrl))
            {
                string ext = System.IO.Path.GetExtension(imgUrl).ToLower();   //上传文件的后缀(小写)

                bitmap = new System.Drawing.Bitmap(Convert.ToInt32(rlSize), Convert.ToInt32(rlSize));

                thumbImg = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(imgUrl));

                System.Drawing.Rectangle rl = new System.Drawing.Rectangle(Convert.ToInt32(pointX), Convert.ToInt32(pointY), Convert.ToInt32(rlSize), Convert.ToInt32(rlSize)); //得到截图矩形

                gps = System.Drawing.Graphics.FromImage(bitmap);                                                                                                                //读到绘图对象

                gps.DrawImage(thumbImg, 0, 0, rl, System.Drawing.GraphicsUnit.Pixel);
                string savePath = conf.UpLoadPath + "/avatar/admin/";
                finalImg = PubClass.GetThumbNailImage(bitmap, finalWidth, finalHeight);
                if (!File.Exists(savePath))   //如果路径不存在,则创建
                {
                    System.IO.Directory.CreateDirectory(ImageHelper.rootpath(savePath));
                }
                string rndname   = DateTime.Now.ToString("yyMMddssfff");
                string finalPath = savePath + rndname + "_small" + ext;
                finalImg.Save(HttpContext.Current.Server.MapPath(finalPath));
                string formconfig = HttpContext.Current.Server.MapPath(@"~/" + imgUrl);
                string toconfig   = HttpContext.Current.Server.MapPath(@"~" + conf.UpLoadPath + "/avatar/admin/" + rndname + "_original" + ext);
                ImageHelper.DeleteImage(formconfig);
                FileTool.CopyFile(formconfig, toconfig, true);

                bitmap.Dispose();
                thumbImg.Dispose();
                gps.Dispose();
                finalImg.Dispose();
                GC.Collect();
                ////写入数据库
                //Lebi_Image model = new Lebi_Image();
                //model.Image = finalPath;
                //model.Keyid = CurrentUser.id;
                //model.Size = "120$120";
                //model.TableName = "avatar";
                //B_Lebi_Image.Add(model);
                //PubClass.FileDel(HttpContext.Current.Server.MapPath(imgUrl));
                Response.Write(finalPath);
            }
        }
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string msg     = "";
            string name    = "";
            string sizestr = "100,100"; //缩略图大小

            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();
            B_WaterConfig      bc    = new B_WaterConfig();
            WaterConfig        mx    = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(conf.UpLoadPath);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }

                string OldImage   = savepath + name;
                string SmallImage = "";
                //生成所有自定义规格
                string[] sizes = sizestr.Split('$');
                foreach (string ss in sizes)
                {
                    string[] s = ss.Split(',');
                    int      w = Convert.ToInt32(s[0]);
                    int      h = Convert.ToInt32(s[1]);
                    SmallImage = name.Replace("_w$h_", "_" + w + "$" + h + "_");
                    ImageHelper.UPLoad(OldImage, savepath, SmallImage, w, h);
                }
                SmallImage = savepath + SmallImage;
                //写入数据库
                Lebi_Image model = new Lebi_Image();
                model.Image     = savepath + name;
                model.Keyid     = 0;
                model.Size      = sizestr;
                model.TableName = "temp";

                B_Lebi_Image.Add(model);
                msg = "OK";
                Response.Write("{\"msg\":\"" + msg + "\",\"ImageSmall\":\"" + SmallImage + "\",\"ImageUrl\":\"" + model.Image + "\"}");
                return;
            }
            msg = Language.Tag("没有选择任何文件", "");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string             msg   = "";
            string             name  = "";
            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();

            B_WaterConfig bc = new B_WaterConfig();
            WaterConfig   mx = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(conf.UpLoadPath);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }
                //if (Shop.LebiAPI.Service.Instanse.Check("imageserver") && WebConfig.Instrance.UpLoadURL != "")
                //{
                //    try
                //    {
                //        string url = WebConfig.Instrance.UpLoadURL;
                //        if (url.Contains("?"))
                //            url += "&filename=" + fileName;
                //        else
                //            url += "?filename=" + fileName;
                //        if (WebConfig.Instrance.ImageServerKey != "")
                //            url += "&key=" + WebConfig.Instrance.ImageServerKey;
                //        string res = HtmlEngine.PostFile(url, ImageHelper.rootpath(savepath + name));
                //        //api = jss.Deserialize<LBAPI>(res);
                //        ImageHelper.DeleteImage(savepath + name);
                //        Response.Write(res);
                //    }
                //    catch (Exception ex)
                //    {
                //        Response.Write("{\"msg\":\"" + ex.Message + "\"}");
                //    }
                //    return;
                //}
                string pos = "";
                Thread thread = new Thread(() => { pos = PostFiles(fileName, savepath, name); });
                thread.IsBackground = true;
                thread.Start();
                thread.Join();
                Response.Write(pos);
                return;
            }
            msg = Language.Tag("没有选择任何文件", "");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string     msg      = "";
            string     name     = "";
            int        theme_id = RequestTool.RequestInt("theme_id", 0);
            Lebi_Theme theme    = B_Lebi_Theme.GetModel(theme_id);

            if (theme == null)
            {
                Response.Write("{\"msg\":\"" + Language.Tag("参数错误") + "\"}");
                return;
            }
            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();
            B_WaterConfig      bc    = new B_WaterConfig();
            WaterConfig        mx    = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(theme.Path_Advert);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }

                string OldImage = savepath + name;
                OldImage = ThemeUrl.CheckURL(OldImage);
                string ImageSmall = name.Replace("_w$h_", "_100$100_");
                string size       = "100$100";


                ImageHelper.UPLoad(OldImage, savepath, ImageSmall, Convert.ToInt32(conf.ImageSmallWidth), Convert.ToInt32(conf.ImageSmallHeight));

                //写入数据库
                Lebi_Image model = new Lebi_Image();
                model.Image     = savepath + name;
                model.Keyid     = 0;
                model.Size      = size;
                model.TableName = "temp";
                B_Lebi_Image.Add(model);
                msg = "OK";
                Response.Write("{\"msg\":\"" + msg + "\",\"url\":\"" + savepath + name + "\",\"Image\":\"" + name + "\",\"ImageSmall\":\"" + ImageSmall + "\"}");
                return;
            }
            msg = Language.Tag("没有选择任何文件", "");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
        private string TestUpload()
        {
            HttpFileCollection files    = HttpContext.Current.Request.Files;
            B_WaterConfig      bc       = new B_WaterConfig();
            WaterConfig        mx       = bc.LoadConfig();
            BaseConfig         conf     = ShopCache.GetBaseConfig();
            string             result   = "";
            string             name     = "";
            StringBuilder      strMsg   = new StringBuilder();
            string             savepath = GetPath(conf.UpLoadPath);

            try
            {
                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    ///'检查文件扩展名字
                    HttpPostedFile postedFile = files[iFile];
                    string         fileName, fileExtension;
                    fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                    fileExtension = System.IO.Path.GetExtension(fileName);
                    if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                    {
                        conf.UpLoadSaveName = "0";
                    }
                    if (conf.UpLoadSaveName == "0")
                    {
                        name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                    }
                    else
                    {
                        name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                    }
                    name = conf.UpLoadRName + name + fileExtension;
                    int status = ImageHelper.SaveImage(postedFile, savepath, name);
                    if (status != 290)
                    {
                        continue;
                    }


                    if (Shop.LebiAPI.Service.Instanse.Check("imageserver") && WebConfig.Instrance.UpLoadURL != "")
                    {
                        try
                        {
                            string res = HtmlEngine.PostFile(WebConfig.Instrance.UpLoadURL, ImageHelper.rootpath(savepath + name));
                            JavaScriptSerializer jss = new JavaScriptSerializer();
                            LBAPI api = jss.Deserialize <LBAPI>(res);
                            result = res;
                        }
                        catch (Exception ex)
                        {
                            result = "{\"msg\":\"" + ex.Message + "\"}";
                        }
                    }
                    else
                    {
                        string OldImage = savepath + name;
                        //string ImageBig = name.Replace("_w$h_", "_" + conf.ImageBigWidth + "$" + conf.ImageBigHeight + "_");
                        //string ImageMedium = name.Replace("_w$h_", "_" + conf.ImageMediumWidth + "$" + conf.ImageMediumHeight + "_");
                        //string ImageSmall = name.Replace("_w$h_", "_" + conf.ImageSmallWidth + "$" + conf.ImageSmallHeight + "_");
                        //string size = conf.ImageBigWidth + "$" + conf.ImageBigHeight + "," + conf.ImageMediumWidth + "$" + conf.ImageMediumHeight + "," + conf.ImageSmallWidth + "$" + conf.ImageSmallHeight;
                        //if (mx.OnAndOff == "1")
                        //{
                        //    ImageHelper.UPLoad(OldImage, savepath, "temp_" + name, Convert.ToInt32(conf.ImageBigWidth), Convert.ToInt32(conf.ImageBigHeight));
                        //    ImageHelper.MakeWater(System.Web.HttpContext.Current.Server.MapPath(savepath) + "temp_" + name, savepath, ImageBig, mx);
                        //    ImageHelper.DeleteImage(savepath + "temp_" + name);
                        //}
                        //else
                        //{
                        //    ImageHelper.UPLoad(OldImage, savepath, ImageBig, Convert.ToInt32(conf.ImageBigWidth), Convert.ToInt32(conf.ImageBigHeight));
                        //}

                        //ImageHelper.UPLoad(OldImage, savepath, ImageMedium, Convert.ToInt32(conf.ImageMediumWidth), Convert.ToInt32(conf.ImageMediumHeight));
                        //ImageHelper.UPLoad(OldImage, savepath, ImageSmall, Convert.ToInt32(conf.ImageSmallWidth), Convert.ToInt32(conf.ImageSmallHeight));


                        ////生成所有规格
                        //string where = "id not in (select id from Lebi_ImageSize where (Width=" + conf.ImageBigWidth + " and Height=" + conf.ImageBigHeight + ") or (Width=" + conf.ImageMediumWidth + " and Height=" + conf.ImageMediumHeight + ") or (Width=" + conf.ImageSmallWidth + " and Height=" + conf.ImageSmallHeight + "))";
                        //List<Lebi_ImageSize> ss = B_Lebi_ImageSize.GetList(where, "");
                        //foreach (Lebi_ImageSize s in ss)
                        //{
                        //    ImageHelper.UPLoad(OldImage, savepath, name.Replace("_w$h_", "_" + s.Width + "$" + s.Height + "_"), s.Width, s.Height);
                        //    size += "," + s.Width + "$" + s.Height;
                        //}
                        //写入数据库
                        Lebi_Image model = new Lebi_Image();
                        model.Image     = savepath + name;
                        model.Keyid     = 0;
                        model.Size      = "";
                        model.TableName = "temp";
                        B_Lebi_Image.Add(model);

                        result = "{\"img\":\"" + OldImage + "\",\"msg\":\"OK\"}";
                    }
                }
            }
            catch (System.Exception ex)
            {
                result = "{\"msg\":\"" + ex.Message + "\"}";
            }
            return(result);
        }
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string             msg       = "";
            string             name      = "";
            int                minWidth  = 80;  //最小宽度
            int                minHeight = 80;  //最小高度
            int                maxWidth  = 200; //最大宽度
            int                maxHeight = 200; //最大高度
            HttpFileCollection files     = HttpContext.Current.Request.Files;
            BaseConfig         conf      = ShopCache.GetBaseConfig();
            B_WaterConfig      bc        = new B_WaterConfig();

            WaterConfig mx = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(ShopCache.GetBaseConfig().UpLoadPath);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                if (RequestTool.RequestSafeString("path") == "Temp")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }
                else
                {
                    string OldImage    = savepath + name;
                    string ImageMedium = name.Replace("_w$h_", "_200$200_");
                    ////写入数据库
                    //Lebi_Image model = new Lebi_Image();
                    //model.Image = savepath + ImageMedium;
                    //model.Keyid = 0;
                    //model.Size = "";
                    //model.TableName = "temp";
                    //B_Lebi_Image.Add(model);


                    //if (originalImage.Width > minWidth && originalImage.Height > minHeight)
                    //{
                    ImageHelper.UPLoad(OldImage, savepath, ImageMedium, maxWidth, maxHeight);
                    //}
                    string FilePath = ImageHelper.rootpath(savepath + ImageMedium);
                    System.Drawing.Image originalImage = System.Drawing.Image.FromFile(FilePath);
                    ImageHelper.DeleteImage(OldImage);
                    Response.Write("{\"msg\":\"OK\",\"ImageUrl\":\"" + savepath + ImageMedium + "\",\"width\":\"" + originalImage.Width + "\",\"height\":\"" + originalImage.Height + "\"}");
                    return;
                }
            }
            msg = Language.Tag("没有选择任何文件");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
Exemple #10
0
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string             msg   = "";
            string             name  = "";
            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();
            B_WaterConfig      bc    = new B_WaterConfig();

            WaterConfig mx = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(ShopCache.GetBaseConfig().UpLoadPath);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                if (RequestTool.RequestSafeString("path") == "verified")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }
                else
                {
                    //写入数据库
                    Lebi_Image model = new Lebi_Image();
                    model.Image     = savepath + name;
                    model.Keyid     = 0;
                    model.Size      = "";
                    model.TableName = "temp";
                    B_Lebi_Image.Add(model);
                    Response.Write("{\"msg\":\"OK\",\"ImageUrl\":\"" + model.Image + "\"}");
                    return;
                }
            }
            msg = Language.Tag("没有选择任何文件");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }
        private string TestUpload()
        {
            HttpFileCollection files    = HttpContext.Current.Request.Files;
            B_WaterConfig      bc       = new B_WaterConfig();
            WaterConfig        mx       = bc.LoadConfig();
            BaseConfig         conf     = ShopCache.GetBaseConfig();
            string             result   = "";
            string             name     = "";
            StringBuilder      strMsg   = new StringBuilder();
            string             savepath = GetPath(conf.UpLoadPath);

            try
            {
                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    ///'检查文件扩展名字
                    HttpPostedFile postedFile = files[iFile];
                    string         fileName, fileExtension;
                    fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                    fileExtension = System.IO.Path.GetExtension(fileName);
                    if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                    {
                        conf.UpLoadSaveName = "0";
                    }
                    if (conf.UpLoadSaveName == "0")
                    {
                        name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                    }
                    else
                    {
                        name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                    }
                    name = conf.UpLoadRName + name + fileExtension;
                    int status = ImageHelper.SaveImage(postedFile, savepath, name);
                    if (status != 290)
                    {
                        continue;
                    }
                    if (Shop.LebiAPI.Service.Instanse.Check("imageserver") && WebConfig.Instrance.UpLoadURL != "")
                    {
                        try
                        {
                            string res = HtmlEngine.PostFile(WebConfig.Instrance.UpLoadURL, ImageHelper.rootpath(savepath + name));
                            res = ImageHelper.GetImageByServerResult(res);
                            ImageHelper.DeleteImage(savepath + name);
                            return(res);
                        }
                        catch (Exception ex)
                        {
                            return(ex.Message);
                        }
                    }

                    string OldImage = savepath + name;

                    result = OldImage;
                }
            }
            catch (System.Exception Ex)
            {
                string err = Ex.Message;
            }
            return(result);
        }
Exemple #12
0
        public void LoadPage()
        {
            if (!AjaxLoadCheck())
            {
                return;
            }
            string             msg   = "";
            string             name  = "";
            HttpFileCollection files = HttpContext.Current.Request.Files;
            BaseConfig         conf  = ShopCache.GetBaseConfig();

            B_WaterConfig bc = new B_WaterConfig();
            WaterConfig   mx = bc.LoadConfig();

            if (files.Count > 0)
            {
                ///'检查文件扩展名字
                HttpPostedFile postedFile = files[0];
                string         savepath = GetPath(conf.UpLoadPath);
                string         fileName, fileExtension;
                fileName      = System.IO.Path.GetFileName(postedFile.FileName);
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (conf.UpLoadSaveName == "" || conf.UpLoadSaveName == null)
                {
                    conf.UpLoadSaveName = "0";
                }
                if (conf.UpLoadSaveName == "0")
                {
                    name = DateTime.Now.ToString("yyMMddssfff") + "_w$h_";
                }
                else
                {
                    name = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_w$h_";
                }
                name = conf.UpLoadRName + name + fileExtension;
                int status = ImageHelper.SaveImage(postedFile, savepath, name);
                if (status != 290)
                {
                    msg = Language.Tag(EX_Type.TypeName(status));
                    Response.Write("{\"msg\":\"" + msg + "\"}");
                    return;
                }
                if (Shop.LebiAPI.Service.Instanse.Check("imageserver") && WebConfig.Instrance.UpLoadURL != "")
                {
                    try
                    {
                        string url = WebConfig.Instrance.UpLoadURL;
                        if (url.Contains("?"))
                        {
                            url += "&filename=" + fileName;
                        }
                        else
                        {
                            url += "?filename=" + fileName;
                        }
                        if (WebConfig.Instrance.ImageServerKey != "")
                        {
                            url += "&key=" + WebConfig.Instrance.ImageServerKey;
                        }
                        string res = HtmlEngine.PostFile(url, ImageHelper.rootpath(savepath + name));
                        //api = jss.Deserialize<LBAPI>(res);
                        ImageHelper.DeleteImage(savepath + name);
                        Response.Write(res);
                    }
                    catch (Exception ex)
                    {
                        Response.Write("{\"msg\":\"" + ex.Message + "\"}");
                    }
                    return;
                }

                string OldImage = savepath + name;
                //string ImageBig = name.Replace("_w$h_", "_" + conf.ImageBigWidth + "$" + conf.ImageBigHeight + "_");
                //string ImageMedium = name.Replace("_w$h_", "_" + conf.ImageMediumWidth + "$" + conf.ImageMediumHeight + "_");
                //string ImageSmall = name.Replace("_w$h_", "_" + conf.ImageSmallWidth + "$" + conf.ImageSmallHeight + "_");
                //string size = conf.ImageBigWidth + "$" + conf.ImageBigHeight + "," + conf.ImageMediumWidth + "$" + conf.ImageMediumHeight + "," + conf.ImageSmallWidth + "$" + conf.ImageSmallHeight;
                string size = "";



                //if (mx.OnAndOff == "1")
                //{
                //    ImageHelper.UPLoad(OldImage, savepath, "temp_" + name, Convert.ToInt32(conf.ImageBigWidth), Convert.ToInt32(conf.ImageBigHeight));
                //    ImageHelper.MakeWater(System.Web.HttpContext.Current.Server.MapPath(savepath) + "temp_" + name, savepath, ImageBig, mx);
                //    ImageHelper.DeleteImage(savepath + "temp_" + name);
                //}
                //else
                //{
                //    ImageHelper.UPLoad(OldImage, savepath, ImageBig, Convert.ToInt32(conf.ImageBigWidth), Convert.ToInt32(conf.ImageBigHeight));
                //}

                //ImageHelper.UPLoad(OldImage, savepath, ImageMedium, Convert.ToInt32(conf.ImageMediumWidth), Convert.ToInt32(conf.ImageMediumHeight));
                //ImageHelper.UPLoad(OldImage, savepath, ImageSmall, Convert.ToInt32(conf.ImageSmallWidth), Convert.ToInt32(conf.ImageSmallHeight));


                ////生成所有规格
                //string where = "id not in (select id from Lebi_ImageSize where (Width=" + conf.ImageBigWidth + " and Height=" + conf.ImageBigHeight + ") or (Width=" + conf.ImageMediumWidth + " and Height=" + conf.ImageMediumHeight + ") or (Width=" + conf.ImageSmallWidth + " and Height=" + conf.ImageSmallHeight + "))";
                //List<Lebi_ImageSize> ss = B_Lebi_ImageSize.GetList(where, "");
                //foreach (Lebi_ImageSize s in ss)
                //{
                //    ImageHelper.UPLoad(OldImage, savepath, name.Replace("_w$h_", "_" + s.Width + "$" + s.Height + "_"), s.Width, s.Height);
                //    size += "," + s.Width + "$" + s.Height;
                //}
                //写入数据库
                Lebi_Image model = new Lebi_Image();
                model.Image     = OldImage;
                model.Keyid     = 0;
                model.Size      = size;
                model.TableName = "Product";
                B_Lebi_Image.Add(model);
                msg = "OK";
                Response.Write("{\"msg\":\"" + msg + "\",\"img\":\"" + OldImage + "\",\"file\":\"" + fileName + "\"}");
                return;
            }
            msg = Language.Tag("没有选择任何文件", "");
            Response.Write("{\"msg\":\"" + msg + "\"}");
        }