Пример #1
0
 /// <summary>
 /// 上传
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnUpload_Click(object sender, EventArgs e)
 {
     try
     {
         foreach (Telerik.WebControls.UploadedFile file in RadUploadContext.Current.UploadedFiles)
         {
             if (file.FileName != "")
             {
                 if (file.ContentLength > FileSize)
                 {
                     StringDeal.Alter("文件大小不能超过" + FileSize / 1024 + "KB");
                 }
                 else if (StringDeal.GetExtNameIsArry(FileType.Split('|'), file.FileName))
                 {
                     string FileExt = file.GetExtension();
                     System.Threading.Thread.Sleep(1000);
                     string FileName = StringDeal.GetGuid() + FileExt;
                     file.SaveAs(this.Server.MapPath(UploadPath + FileName), true);
                     Response.StatusCode = 200;
                     #region 生成缩略图
                     if (!String.IsNullOrEmpty(ThumbnailSize) && StringDeal.GetExtNameIsArry("gif|jpg|jpeg|png|bmp".Split(','), FileName))
                     {
                         Thumbnail th = new Thumbnail();
                         th.FileName          = FileName;
                         th.OriginalImagePath = UploadPath;
                         th.Width             = StringDeal.ToInt(ThumbnailSize.Split('*')[0]);
                         th.Height            = StringDeal.ToInt(ThumbnailSize.Split('*')[1]);
                         th.MakeThumbnail();
                     }
                     #endregion
                     this.uptd.Visible      = false;
                     this.but_close.Visible = false;
                     this.but_over.Visible  = true;
                     this.btnUpload.Visible = false;
                     Response.Write("<script language='javascript' type='text/javascript'>window.parent.$('" + InputName + "').value='" + FileName + "';window.parent.$('upid').innerHTML = '删除';</script>");
                 }
             }
         }
     }
     catch
     {
     }
 }
Пример #2
0
    /// <summary>
    /// 提交后保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string UploadFileName = "";
        string UploadType     = Request.Form["Upload"];                         //文件方式
        int    FileSize       = StringDeal.ToInt(GetConfig.File("FileSize"));   //文件最大上传
        string UploadFilePath = GetConfig.File("UploadFilePath");               //文件上传路径
        string SelectFile     = Request.Form["SelectFile"];                     //选择服务器上的文件名
        string WebUrl         = Request.Form["WebUrl"].Replace("'", "&acute;"); //网络文件地址

        if (String.IsNullOrEmpty(UploadFilePath))
        {
            UploadFilePath = "../../Upload/File/";
        }
        if (FileSize == 0)
        {
            FileSize = 1020000;
        }
        else
        {
            FileSize = FileSize * 1024;
        }
        if (UploadType == "upload1")
        {
            UploadFilePath = UploadFilePath + DateTime.Today.ToString("yyyyMM") + "/";
            Files.CreateFolder(UploadFilePath);
            #region 大文件上传
            try
            {
                foreach (Telerik.WebControls.UploadedFile file in RadUploadContext.Current.UploadedFiles)
                {
                    if (file.FileName != "")
                    {
                        if (file.ContentLength > FileSize)
                        {
                            StringDeal.Alter("文件大小不能超过" + FileSize / 1024 + "KB");
                        }
                        else if (FormatUploadType(file.FileName))
                        {
                            string FileExt = file.GetExtension();
                            System.Threading.Thread.Sleep(1000);
                            string FileName = StringDeal.GetGuid() + FileExt;
                            file.SaveAs(this.Server.MapPath(UploadFilePath + FileName), true);
                            Response.StatusCode = 200;
                            UploadFileName     += UploadFilePath + FileName + ",";
                        }
                        else
                        {
                            StringDeal.Alter("上传文件格式不正确!");
                        }
                    }
                }
            }
            catch
            {
            }
            #endregion
        }
        else if (UploadType == "upload2")
        {
            #region  择服务器上的保存
            UploadFileName = SelectFile;
            #endregion
        }
        else
        {
            #region 输入网络文件地址保存
            UploadFileName = WebUrl;
            #endregion
        }
        this.JavascriptServer.Text = "BackVal('" + InputName + "','" + UploadFileName.Trim(',') + "');</script>";
    }
Пример #3
0
    /// <summary>
    /// 提交后保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        // mapFilePath = HttpContext.Current.Server.MapPath(filePath);
        string UploadImageName = "";
        string UploadType      = Request.Form["Upload"];                            //图片方式
        int    ImageSize       = StringDeal.ToInt(GetConfig.Image("ImageSize"));    //图片最大上传
        string UploadImagePath = GetConfig.Image("UploadImagePath");                //图片上传路径
        string ImageType       = GetConfig.Image("ImageType");                      //允许图片类型
        bool   IsThumbnail     = StringDeal.ToBool(Request.Form["IsThumbnail"]);    //是否生成缩略图
        int    ThumbWidth      = StringDeal.ToInt(Request.Form["ThumbWidth"]);      //缩略图宽
        int    ThumbHeight     = StringDeal.ToInt(Request.Form["ThumbHeight"]);     //缩略图高
        string ThumbMode       = Request.Form["ThumbMode"];
        bool   IsWatermark     = StringDeal.ToBool(Request.Form["IsWatermark"]);    //加水印
        string WatermarkImage  = GetConfig.Image("WatermarkImage");                 //水印图地址
        int    WatermarkPos    = StringDeal.ToInt(GetConfig.Image("WatermarkPos")); //水印放置位置
        string SelectImage     = Request.Form["SelectImage"];                       //选择服务器上的图片名
        string WebUrl          = Request.Form["WebUrl"];                            //网络图片地址

        if (String.IsNullOrEmpty(UploadImagePath))
        {
            UploadImagePath = "../../Upload/image/";
        }
        if (ImageSize == 0)
        {
            ImageSize = 1020000;
        }
        else
        {
            ImageSize = ImageSize * 1024;
        }
        if (String.IsNullOrEmpty(ImageType))
        {
            ImageType = "jpg,gif,png,bmp,jpeg";
        }
        if (UploadType == "upload1")
        {
            UploadImagePath = UploadImagePath + DateTime.Today.ToString("yyyyMM") + "/";
            Files.CreateFolder(UploadImagePath);
            #region 大文件上传
            try
            {
                foreach (Telerik.WebControls.UploadedFile file in RadUploadContext.Current.UploadedFiles)
                {
                    System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream);
                    if (file.FileName != "")
                    {
                        if (file.ContentLength > ImageSize)
                        {
                            StringDeal.Alter("文件大小不能超过" + ImageSize / 1024 + "KB");
                        }
                        else if (StringDeal.GetExtNameIsArry(ImageType.Split(','), file.FileName))
                        {
                            string FileExt = file.GetExtension();
                            System.Threading.Thread.Sleep(1000);
                            string FileName = StringDeal.GetGuid() + FileExt;
                            file.SaveAs(this.Server.MapPath(UploadImagePath + FileName), true);
                            Response.StatusCode = 200;
                            #region 生成缩略图
                            if (IsThumbnail)
                            {
                                Thumbnail th = new Thumbnail();
                                th.Mode              = ThumbMode;
                                th.FileName          = FileName;
                                th.OriginalImagePath = UploadImagePath;
                                th.Width             = ThumbWidth;
                                th.Height            = ThumbHeight;
                                th.MakeThumbnail();
                            }
                            #endregion
                            UploadImageName = UploadImagePath + FileName;
                        }
                        else
                        {
                            StringDeal.Alter("上传图片格式不正确!");
                        }
                    }
                    image.Dispose();
                }
            }
            catch
            {
            }
            #endregion
        }
        else if (UploadType == "upload2")
        {
            #region  择服务器上的保存
            if (IsThumbnail)
            {
                if (SelectImage != string.Empty)
                {
                    if (!HXD.Common.Utils.IsUrl(SelectImage))
                    {
                        if (HXD.Common.Utils.isPhotoIco(SelectImage))
                        {
                            System.IO.File.Delete(Server.MapPath("~" + HXD.Common.Utils.PhotoIco(SelectImage)));
                        }
                        string FileName = string.Empty;
                        FileName        = SelectImage.Substring(SelectImage.LastIndexOf('/') + 1);
                        UploadImagePath = SelectImage.Remove(SelectImage.LastIndexOf('/') + 1);
                        Thumbnail th = new Thumbnail();
                        th.Mode              = ThumbMode;
                        th.FileName          = FileName;
                        th.OriginalImagePath = UploadImagePath;
                        th.Width             = ThumbWidth;
                        th.Height            = ThumbHeight;
                        th.MakeThumbnail();
                    }
                }
            }
            UploadImageName = SelectImage;
            #endregion
        }
        else
        {
            #region 输入网络图片地址保存
            UploadImageName = WebUrl;
            #endregion
        }

        Response.Write("<script language='javascript' type='text/javascript'>window.parent.loadinndlg().document.getElementById('" + InputName + "').value='" + UploadImageName + "';window.parent.cancel();</script>");
    }