日期:2013-09-08  浏览次数:20423 次

功能:
1。把图片文件(JPG GIF PNG)上传,
2。保存到指定的路径(在web.config中设置路径,以文件的原有格式保存),
3。并自动生成指定宽度的(在web.config中设置宽度)
4。和指定格式的(在web.config中指定缩略图的格式)
5。和原图比例相同的缩略图(根据宽度和原图的宽和高计算所略图的高度)
6。可以判断是否已经存在文件
7。如果不覆盖,则给出错误
8。如果选中"覆盖原图"checkbox,则覆盖原图。
9。可以根据要求,在webform上设置1个以上的file input和相应的checkbox
10。并在文件上传完毕后,显示原图的文件名,尺寸,字节,和
11。缩略图的文件名尺寸。
12。缩略图的文件名格式:原图+"_thumb."+指定格式,如:test.jpg_thumb.gif,以便于管理。

--------------------
public void UploadFile(object sender, System.EventArgs e)
        {
            
                string imgNameOnly, imgNameNoExt, imgExt;
                string imgThumbnail;
                int erroNumber = 0;
                System.Drawing.Image oriImg, newImg;
                string strFePicSavePath = ConfigurationSettings.AppSettings["FePicSavePath"].ToString();
                string strFePicThumbFormat = ConfigurationSettings.AppSettings["FePicThumbFormat"].ToString().ToLower();
                int intFeThumbWidth = Int32.Parse(ConfigurationSettings.AppSettings["FePicThumbWidth"]);
                string fileExt;

                StringBuilder picInfo = new StringBuilder();
            
            if(Page.IsValid)
            {
            

                for(int i = 0;i < Request.Files.Count; i++)
                {
                    HttpPostedFile PostedFile = Request.Files[i];
                    fileExt = (System.IO.Path.GetExtension(PostedFile.FileName)).ToString().ToLower();
                
                    imgNameOnly = System.IO.Path.GetFileName(PostedFile.FileName);
                    if(fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
                    {

                        if(System.IO.File.Exists(strFePicSavePath + imgNameOnly) && (checkboxlistRewrite.Items[i].Selected == false))