publicHashtable?upFile(HttpContext?cxt,?string?pathbase,?string[]?filetype,?int?size)
{
pathbase?=?pathbase?+?"";
uploadpath?=?cxt.Server.MapPath(pathbase);//获取文件上传路径
try
{
uploadFile?=?cxt.Request.Files[0];
originalName?=?uploadFile.FileName;
//目录创建
createFolder();
//格式验证
if?(checkType(filetype))
{
//不允许的文件类型
state?=?"\u4e0d\u5141\u8bb8\u7684\u6587\u4ef6\u7c7b\u578b";
}
//大小验证
if?(checkSize(size))
{
//文件大小超出网站限制
state?=?"\u6587\u4ef6\u5927\u5c0f\u8d85\u51fa\u7f51\u7ad9\u9650\u5236";
}
//保存
if?(state?==?"SUCCESS")
{
filename?=?NameFormater.Format(cxt.Request["fileNameFormat"],?originalName);
var?testname?=?filename;
var?ai?=?1;
while?(File.Exists(uploadpath?+?testname))
{
testname?=Path.GetFileNameWithoutExtension(filename)?+?"_"?+?ai++?+?Path.GetExtension(filename);?
}
uploadFile.SaveAs(uploadpath?+?testname);
URL?=?pathbase?+?testname;
}
}
catch?(Exception)
{
//?未知错误
state?=?"\u672a\u77e5\u9519\u8bef";
URL?=?"";
}
return?getUploadInfo();
}
本文来自作者[友佳鑫]投稿,不代表千泰号立场,如若转载,请注明出处:https://m1.hr8848.cn/yule/202508-21334.html
评论列表(3条)
我是千泰号的签约作者“友佳鑫”
本文概览:publicHashtable?upFile(HttpContext?cxt,?string?pathbase,?string[]?filetype,?int?size){pa...
文章不错《为什么我的手机的移动网络没用了》内容很有帮助