/// <summary> /// 创建图像 /// </summary> /// <param name="imgPath">图片的相对服务器跟路径</param> /// <returns></returns> public int CreatThumbnail(string imgPath) { SRCom srCom = new SRCom(); string fileNewName = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");//重命名文件名,防止重复 string imgAbsPath = AppDomain.CurrentDomain.BaseDirectory + imgPath;//原图像绝对地址 Image image = Image.FromFile(imgAbsPath); //利用Image对象装载源图像 string imgExt = "."+srCom.GetFileExt(imgPath); NewImgName = fileNewName + imgExt; //MiniImgName = "mini" + fileNewName + imgExt; SaveThumbnail(NewImgPath, NewImgName, image, MaxImgWidth, ImgCompressLever);//存储新图像 // SaveThumbnail(MiniImgPath, MiniImgName, image, MiniImgWidth, MiniImgCompressLever);//存储缩略图 image.Dispose(); //srCom.DeleteFile(imgPath);//删除原图像 return 0; }
/// <summary> /// 上传文件 /// </summary> /// <param name="file"></param> /// <returns>0为文件不存在,1文件大小为0,2文件大小超过4M,3不存在文件类型,4不允许的上传类型,5上传成功</returns> public int UploadFile(HttpPostedFile file) { SRCom srCom = new SRCom(); string FilesPath = AppDomain.CurrentDomain.BaseDirectory + filesPath; if (null == file) return 5;//文件不存在 if (!(file.ContentLength > 0)) return 1;//文件大小为0 if (file.ContentLength > 4194304) return 2;//文件大小超过4M fileName = file.FileName;//获取文件名 fileExt = Path.GetExtension(file.FileName);//获取文件类型 if (null == fileExt) return 3;//不存在文件类型 // 截取上载文件后缀名,不含“.” string extension = srCom.GetFileExt(fileName); if (("," + AllowFileExt + ",").IndexOf("," + extension + ",") < 0) return 4;//err = "上传文件扩展名必需为:" + upext; //检查目录是否存在,不存在则创建 if (!Directory.Exists(FilesPath)) { Directory.CreateDirectory(FilesPath); } string vsnewname = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");//重命名文件名,防止重复 fileName = vsnewname + fileExt; string path = FilesPath + fileName; file.SaveAs(path); return 0; }