Пример #1
0
        /// <summary>
        /// 添加图像命令
        /// </summary>
        void AddImg()
        {
            UP_img up_img = new UP_img();

            if (FileUpload1.HasFile)
            {
                string name            = FileUpload1.PostedFile.FileName;
                string fileContentType = FileUpload1.PostedFile.ContentType;
                string fileContentSize = FileUpload1.PostedFile.ContentLength.ToString();

                // 客户端文件路径
                FileInfo file          = new FileInfo(name);
                string   fileName      = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + name.Substring(name.LastIndexOf("."), name.Length - name.LastIndexOf(".")); // 文件名称
                string   webFilePath   = Server.MapPath(FileRootPath);                                                                                              // 服务器端文件路径
                string   webFilePath_s = Server.MapPath(FileRootPath + "s_");                                                                                       // 服务器端缩略图路径
                if (!Directory.Exists(webFilePath))                                                                                                                 //判断是否存在
                {
                    Directory.CreateDirectory(webFilePath);                                                                                                         //创建新路径
                    try
                    {
                        FileUpload1.SaveAs(webFilePath + fileName);                                       // 使用 SaveAs 方法保存文件

                        if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/png")
                        {
                            string[] Size = DropDownList_ImgSize.SelectedValue.Split(',');
                            up_img.MakeThumbnail(webFilePath + fileName, webFilePath_s + fileName, Convert.ToInt32(Size[0]), Convert.ToInt32(Size[1]), "W");              // 生成缩略图方法
                        }
                        XmlNew(fileName, FileRootPath.Replace("~", ""), fileContentType, fileContentSize);
                        this.ListBox_img.Items.Add(new ListItem(fileName, fileName));
                    }
                    catch
                    {
                        Response.Write("文件上传失败!");
                    }
                }
                else
                {
                    try
                    {
                        FileUpload1.SaveAs(webFilePath + fileName);                                       // 使用 SaveAs 方法保存文件

                        if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/png")
                        {
                            string[] Size = DropDownList_ImgSize.SelectedValue.Split(',');
                            up_img.MakeThumbnail(webFilePath + fileName, webFilePath_s + fileName, Convert.ToInt32(Size[0]), Convert.ToInt32(Size[1]), "W");              // 生成缩略图方法
                        }
                        XmlNew(fileName, FileRootPath.Replace("~", ""), fileContentType, fileContentSize);
                        this.ListBox_img.Items.Add(new ListItem(fileName, fileName));
                    }
                    catch
                    {
                        Response.Write("文件上传失败!");
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 添加形象图方法 Adds the img.
        /// </summary>
        /// <param name="path">The path.</param>
        void AddImg(string path)
        {
            UP_img up_img = new UP_img();

            if (FileUpload1.HasFile)
            {
                string fileContentType = FileUpload1.PostedFile.ContentType;
                if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")
                {
                    string   name        = FileUpload1.PostedFile.FileName;                                                                                           // 客户端文件路径
                    FileInfo file        = new FileInfo(name);
                    string   fileName    = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + name.Substring(name.LastIndexOf("."), name.Length - name.LastIndexOf(".")); // 文件名称
                    string   webFilePath = Server.MapPath(this.WEBSITE_UP_FILES + path);                                                                              // 服务器端文件路径

                    string webFilePath_s = Server.MapPath(this.WEBSITE_UP_FILES + path + "s_");                                                                       // 服务器端缩略图路径

                    if (!Directory.Exists(webFilePath))                                                                                                               //判断是否存在
                    {
                        Directory.CreateDirectory(webFilePath);                                                                                                       //创建新路径
                    }
                    try
                    {
                        this.FileUpload1.SaveAs(webFilePath + "_" + fileName);                                                                                 // 使用 SaveAs 方法保存文件
                        string[] Size = DropDownList_ImgSize.SelectedValue.Split(',');
                        up_img.MakeThumbnail(webFilePath + "_" + fileName, webFilePath_s + fileName, Convert.ToInt32(Size[0]), Convert.ToInt32(Size[1]), "W"); // 生成缩略图方法
                        up_img.AddWaterPic(webFilePath + "_" + fileName, webFilePath + fileName, Server.MapPath("~/App_Data/Water.png"));
                        //FCKeditor1.Value = FCKeditor1.Value + "<img src=" + Config.ROYcmsConfig.Get_Config().web_host + this.AppendixPath.Replace("~/", "") + path + fileName + " />";
                        this.txtpic.Text = fileName;
                        //this.pic = "<a href='" + this.AppendixPath.Replace("~/", "/") + path + fileName + "' target='_blank'><img src='/pic.gif' alt='查看上传的图片' width='16' height='16' border='0'></a> ";
                        ROYcms.Common.MessageBox.Show(this, "上载成功!");
                    }
                    catch
                    {
                        ROYcms.Common.MessageBox.Show(this, "文件上传失败!");
                        // Response.Write("文件上传失败!");
                    }
                }
                else
                {
                    ROYcms.Common.MessageBox.Show(this, "文件类型不符!");
                    // Response.Write("文件类型不符!");
                }
            }
        }