Example #1
0
        /**
         * 上传文件的主处理方法
         * @param HttpContext
         * @param string
         * @param  string[]
         *@param int
         * @return Hashtable
         */
        public Hashtable upFile(HttpContext cxt)
        {
            try
            {
                uploadFile   = cxt.Request.Files[0];
                originalName = uploadFile.FileName;
                currentType  = getFileExt();

                var localDirectoryPath = PathUtils.GetUserUploadDirectoryPath(string.Empty);
                var localFileName      = PathUtils.GetUserUploadFileName(originalName);
                var localFilePath      = PathUtils.Combine(localDirectoryPath, localFileName);
                var fileExtName        = PathUtils.GetExtension(originalName);

                //string pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
                //uploadpath = cxt.Server.MapPath(pathbase);//获取文件上传路径

                //格式验证
                //if (checkType(filetype))
                //{
                //    state = "不允许的文件类型";
                //}
                ////大小验证
                //if (checkSize(size))
                //{
                //    state = "文件大小超出网站限制";
                //}
                //保存图片
                if (state == "SUCCESS")
                {
                    uploadFile.SaveAs(localFilePath);
                    URL = PageUtils.GetRootUrlByPhysicalPath(localFilePath);
                    //URL = pathbase + filename;
                }
            }
            catch (Exception e)
            {
                state = e.Message;
                URL   = "";
            }
            return(getUploadInfo());
        }