Example #1
0
        string UploadImage(string url)
        {
            string ChannelPath = Server.MapPath(Channel.ChannelUrlPath);

            if (TitleImageFileUpload.FileName.Length < 1)
            {
                Messages.ShowError("图片不能为空!");
            }
            if (!CDHelper.CanUpload(TitleImageFileUpload.FileName))
            {
                Messages.ShowError("不支持上传该类型的图片。");
            }

            string logoName = url.Replace("/", "_");

            if (logoName.EndsWith("_"))
            {
                logoName = logoName.Remove(logoName.Length - 1);
            }
            if (logoName.StartsWith("_"))
            {
                logoName = logoName.Remove(0, 1);
            }
            string path              = string.Format("{0}\\{1}{2}", ChannelPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));
            string ImagefileName     = string.Format("{0}/{1}{2}", Channel.ChannelUrlPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));
            string thumbnailFilePath = string.Format("{0}\\{1}_S{2}", ChannelPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));

            if (!Directory.Exists(ChannelPath))
            {
                Directory.CreateDirectory(ChannelPath);
            }

            try
            {
                TitleImageFileUpload.SaveAs(path);
                ImageUtils.MakeThumbnail(path, thumbnailFilePath, 110, 90, "W");
            }
            catch (IOException)
            {
                Messages.ShowError("图片上传失败,请重试!");
            }

            return(ImagefileName);
        }
Example #2
0
        void UploadImageFile()
        {
            if (ImageFileUpload.FileName.Length < 1)
            {
                this.Messages.ShowError("请选择图片文件再上传!");
                return;
            }
            if (!CDHelper.CanUpload(ImageFileUpload.FileName))
            {
                this.Messages.ShowError("系统不支持上传该类型的图片,请在本地转换为gif或jpg格式的再试。");
                return;
            }

            try
            {
                UploadAndCreateThumbnails(Path.GetFileName(ImageFileUpload.FileName));
                Response.Redirect(Request.RawUrl + "&uploaded=" + Path.GetFileName(ImageFileUpload.FileName));
            }
            catch (IOException)
            {
                this.Messages.ShowError("图片上传失败,请重试!");
                return;
            }
        }