Exemple #1
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="errorStr">错误信息</param>
        /// <param name="file">流文件</param>
        /// <param name="FileType">允许的文件类型</param>
        /// <param name="FileMaxSize">允许的最大值</param>
        /// <param name="strSaveFileWebPath">文件保存Web相对路劲</param>
        /// <param name="strSaveFileName">文件保存名称</param>
        /// <returns></returns>
        public static string UploadFile(ref string errorStr, HttpPostedFileBase file, string FileType, long FileMaxSize, string strSaveFileWebPath, string strSaveFileName = "")
        {
            if (file == null || file.ContentLength == 0)
            {
                return("");
            }

            //验证文件格式
            if (!CheckFileType(file, FileType))
            {
                errorStr = "文件格式不正确!";
                return("");
            }

            //验证文件大小

            if (!CheckFileSize(file, FileMaxSize))
            {
                errorStr = "上传文件大小不能超过" + FileMaxSize + "KB!";
                return("");
            }

            //后缀
            string extName = Path.GetExtension(file.FileName);

            //文件名称
            if (strSaveFileName == "")
            {
                strSaveFileName = GetNewFileName() + "$$" + file.FileName;
            }

            //文件保存物理绝对路劲
            string dirAbsolutePath = DirFile.GetServerPath(strSaveFileWebPath);

            try
            {
                //正式上传
                Upload(file, dirAbsolutePath, strSaveFileName);

                return(strSaveFileWebPath + strSaveFileName);
            }
            catch (Exception ex)
            {
                return("");
            }
        }
Exemple #2
0
 public void  GetVersion()
 {
     string                 baseDirectory = DirFile.GetServerPath("/Xml/AppVersion.xml");
     AppVersionModels       models        = (AppVersionModels)ConvertHelper.XmlDeserialize(typeof(AppVersionModels), baseDirectory);
     List <AppVersionModel> list          = new List <AppVersionModel>(models.Items);
 }
Exemple #3
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="upImg">文件流</param>
        /// <param name="maxSize">限制图片最大值kb</param>
        /// <param name="maxWidth">像素最大宽度</param>
        /// <param name="maxHeight">像素最大高度</param>
        /// <param name="isThumbnail">是否生成缩略图(1:生成等比缩放的;2:不生成;3:生成非等比缩放的)</param>
        /// <param name="targetWidth">缩略后的宽度</param>
        /// <param name="targetHeight">缩略后的高度</param>
        /// <returns></returns>
        public static string UploadImg(ref string errorStr, HttpPostedFileBase upImg, int maxSize = 1000000, int maxWidth = 100000, int maxHeight = 100000, int isThumbnail = 2, double targetWidth = 50, double targetHeight = 50)
        {
            if (upImg == null || upImg.ContentLength == 0)
            {
                return("");
            }

            //验证文件格式
            string allowedImage = "gif,img,imge";

            if (!CheckFileType(upImg, allowedImage))
            {
                errorStr = "图片格式不正确!";
                return("");
            }

            //验证文件大小
            int ImageMaxSize = 2048;

            if (!CheckFileSize(upImg, ImageMaxSize))
            {
                errorStr = "上传图片大小不能超过" + ImageMaxSize + "KB!";
                return("");
            }

            //验证图片宽高
            if (!CheckImgWidthAndHeight(upImg, maxWidth, maxHeight))
            {
                errorStr = "图片格式有误,请上传[" + maxWidth + "*" + maxHeight + "]以内的图片!";
                return("");
            }

            //后缀
            string extName = Path.GetExtension(upImg.FileName);
            //文件名称
            string fileName = GetNewFileName() + extName;

            //文件保存Web相对路劲
            string dirWebPath = "/upload/";
            //文件保存物理绝对路劲
            string dirAbsolutePath = DirFile.GetServerPath(dirWebPath);

            try
            {
                //正式上传
                Upload(upImg, dirAbsolutePath, fileName);

                //缩略图保存路径
                string ThumbnailAbsolutePath = dirAbsolutePath + "Thumbnail/";
                if (isThumbnail == 1)
                {
                    //生成缩略图片
                    PTImage.ImageZoomAuto(dirAbsolutePath + fileName, ThumbnailAbsolutePath, fileName, targetWidth, targetHeight);
                }
                else if (isThumbnail == 3)
                {
                    PTImage.Compress(dirAbsolutePath + fileName, ThumbnailAbsolutePath, (int)targetWidth, (int)targetHeight);
                }

                return(dirWebPath + fileName);
            }
            catch (Exception ex)
            {
                return("");
            }
        }