Ejemplo n.º 1
0
        public ActionResult ImageManager(string action)
        {
            string[] paths    = { "Image", "Other" }; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时
            string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
            String   str      = String.Empty;

            if (_Request == null)
            {
                _Request = Request;
            }
            if (action == "get")
            {
                UploadFileManager.httpContext = _Request.RequestContext.HttpContext;
                foreach (string path in paths)
                {
                    var    cfg      = UploadFileManager.GetUploadConfig("UEImage");
                    string basePath = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/" + path;
                    if (WebConfigHelper.GetAppSettingValue("IsLinux") != "true")
                    {
                        basePath = basePath.Replace("/", "\\");
                    }
                    DirectoryInfo info = new DirectoryInfo(basePath);
                    //目录验证
                    if (info.Exists)
                    {
                        DirectoryInfo[] infoArr = info.GetDirectories();
                        foreach (DirectoryInfo tmpInfo in infoArr)
                        {
                            foreach (FileInfo fi in tmpInfo.GetFiles())
                            {
                                if (Array.IndexOf(filetype, fi.Extension) != -1)
                                {
                                    str += cfg.Folder + "/" + path + "/" + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue";
                                }
                            }
                        }
                    }
                }
            }
            return(Content(str));
        }
        public ActionResult ImageManager(string action)
        {
            string[] paths    = { "Image", "Other" }; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时
            string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
            String   str      = String.Empty;

            if (_Request == null)
            {
                _Request = Request;
            }
            if (action == "get")
            {
                string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString();
                foreach (string path in paths)
                {
                    var           cfg      = UploadFileManager.GetUploadConfig("UEImage");
                    string        basePath = WebHelper.MapPath("/") + pathFlag + cfg.Folder + pathFlag + path;
                    DirectoryInfo info     = new DirectoryInfo(basePath);
                    //目录验证
                    if (info.Exists)
                    {
                        DirectoryInfo[] infoArr = info.GetDirectories();
                        foreach (DirectoryInfo tmpInfo in infoArr)
                        {
                            foreach (FileInfo fi in tmpInfo.GetFiles())
                            {
                                if (Array.IndexOf(filetype, fi.Extension) != -1)
                                {
                                    str += cfg.Folder + "/" + path + "/" + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue";
                                }
                            }
                        }
                    }
                }
            }
            return(Content(str));
        }
Ejemplo n.º 3
0
        public ActionResult ScrawlUp(HttpPostedFileBase upfile, string content)
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            UploadFileManager.httpContext = _Request.RequestContext.HttpContext;
            var cfg = UploadFileManager.GetUploadConfig("UEImage");

            if (upfile != null)
            {
                string path  = string.Empty;
                string state = "SUCCESS";
                //上传图片
                try
                {
                    path = UploadFile(upfile, "UEImage", "Temp");
                }
                catch (Exception ex)
                {
                    return(Json(new { state = ex.Message }));
                }
                return(Content("<script>parent.ue_callback('" + path + "','" + state + "')</script>"));//回调函数
            }
            else
            {
                //上传图片
                string     url      = string.Empty;
                string     state    = "SUCCESS";
                FileStream fs       = null;
                string     pathFlag = "\\";
                if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
                {
                    pathFlag = "/";
                }
                try
                {
                    string dir  = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Other";
                    string path = DateTime.Now.ToString("yyyyMM");
                    dir = dir + "/" + path;
                    if (pathFlag == "\\")
                    {
                        dir = dir.Replace("/", "\\");
                    }
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    string filename = System.Guid.NewGuid() + ".png";
                    fs = System.IO.File.Create(dir + pathFlag + filename);
                    byte[] bytes = Convert.FromBase64String(content);
                    fs.Write(bytes, 0, bytes.Length);
                    url = cfg.Folder + "/Other/" + path + "/" + filename;
                }
                catch (Exception e)
                {
                    state = "未知错误:" + e.Message;
                    url   = "";
                }
                finally
                {
                    fs.Close();
                    string tempDir = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Temp";
                    if (pathFlag == "\\")
                    {
                        tempDir = tempDir.Replace("/", "\\");
                    }
                    DirectoryInfo info = new DirectoryInfo(tempDir);
                    if (info.Exists)
                    {
                        DirectoryInfo[] infoArr = info.GetDirectories();
                        foreach (var item in infoArr)
                        {
                            string str = tempDir + pathFlag + item.Name;
                            Directory.Delete(str, true);
                        }
                    }
                }
                return(Json(new { url = url, state = state }));
            }
        }