fl0at 发表于 2015-4-6 03:46:01

看此源码,可否突破上传

public ErrorList Upload(FileUpload fu, string newFilename = "")
{
        ErrorList errorList = new ErrorList();
        ErrorList result;
        if (fu == null)
        {
                errorList.AddError("", "请选择上传的文件!");
                result = errorList;
        }
        else
        {
                this.FileSize = fu.PostedFile.ContentLength;
                this.FileType = fu.PostedFile.ContentType;
                this.FileOldName = fu.PostedFile.FileName;
                this.FileExtName = this.GetFileExtName(this.FileOldName); //获取 .jpg
                this.Filename = newFilename + this.FileExtName;
                if (string.IsNullOrEmpty(newFilename))
                {
                        this.Filename = this.CreateNewFilename(this.FileExtName);
                }
                if (this.FileSize == 0)
                {
                        errorList.AddError("", "请选择上传的文件!");
                }
                else
                {
                        if (this.FileSize > this.SetAllowMaxFileSize)
                        {
                                errorList.AddError("", "选择的文件太大!");
                        }
                }
                if (errorList.HasError())
                {
                        result = errorList;
                }
                else
                {
                        this.IsImage = this.CheckIsImage(fu.PostedFile.InputStream);
                        if (this.IsImage)
                        {
                                if (!string.IsNullOrEmpty(this.SetAllowFileType))
                                {
                                        if (!Text.CheckInChar(this.SetAllowFileType, this.FileExtName))
                                        {
                                                errorList.AddError("", "上传的文件扩展名不被允许!");
                                        }
                                }
                        }
                        else
                        {
                                if (!Text.CheckInChar(this.SetAllowFileType, this.FileExtName))
                                {
                                        errorList.AddError("", "上传的文件扩展名不被允许!!");
                                }
                                string typeNumber = this.GetTypeNumber(fu);
                                if (!Text.CheckInChar(this.SetAllowFileType, typeNumber))
                                {
                                        errorList.AddError("", "上传的文件类型不被允许!!!" + typeNumber);
                                }
                        }
                        if (errorList.HasError())
                        {
                                result = errorList;
                        }
                        else
                        {
                                try
                                {
                                        if (!Directory.Exists(this.SetSavePath))
                                        {
                                                Directory.CreateDirectory(this.SetSavePath);
                                        }
                                        if (this.IsImage && (this.SetWidth > 0 || this.SetHeight > 0))
                                        {
                                                string text = this.SetSavePath + "/temp" + this.Filename;
                                                fu.PostedFile.SaveAs(text);
                                                errorList.AddErrors(this.MakeThumbnail(text, this.SetSavePath + "/" + this.Filename, this.SetWidth, this.SetHeight, this.SetZoomMode));
                                                this.FileSize = this.GetFileSize(this.SetSavePath + "/" + this.Filename);
                                                File.Delete(text);
                                        }
                                        else
                                        {
                                                fu.PostedFile.SaveAs(this.SetSavePath + "/" + this.Filename);
                                        }
                                }
                                catch
                                {
                                        errorList.AddError("", "发生错误!");
                                }
                                result = errorList;
                        }
                }
        }
        return result;
}

上传1. 重命名为XXXXXXXXXXXXXX.   无后缀,相反,上传asp,cer,aspx,返回不允许该文件扩展名。求讨论啊。

小安 发表于 2015-4-9 11:59:06

上传图片格式也不行吗?

fl0at 发表于 2015-4-9 23:16:35

小安 发表于 2015-4-9 11:59
上传图片格式也不行吗?

可以。。。
页: [1]
查看完整版本: 看此源码,可否突破上传