📄 config.ascx
字号:
<%@ Control EnableViewState="false" AutoEventWireup="false" %>
<%@ Import Namespace="System.IO" %>
<script language="c#" type="c#" runat="server" >
public string fileStr = "gif|jpg|jpeg";
//~~~~~~~~~~~~~~~~~~~~~~Config upload File Path~~~~~~~~~~~~~~~~~~~~~~~~
public string UploadImagePath = "/EditorExmB/upload/";
public string UploadFlashPath = "/EditorExmB/flash/";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public string UploadImg(System.Web.UI.HtmlControls.HtmlInputFile FP,string path,string ty)
{
string photoPath = FP.PostedFile.FileName;
if (photoPath.Trim().Length == 0)
{
throw new Exception("文件地址长度不能小于0");
}
string fileName = photoPath;
if (Context.Request.Browser.Type.ToLower() == "ie" && Double.Parse(Context.Request.Browser.Version) < 7.0)
{
if (photoPath.IndexOf('\\')==-1)
{
throw new Exception("文件地址格式错误!!");
}
fileName = photoPath.Substring(photoPath.LastIndexOf('\\')+1);
}
string[] ftype = fileName.Split('.');
if (!isCurFile(ftype[ftype.Length - 1].ToLower()))
{
throw new Exception("上传格式错误!");
}
string fName = DateTime.Now.ToFileTimeUtc().ToString() + ty + "." + ftype[ftype.Length - 1].ToLower();
cfrFile(Server.MapPath(path));
try
{
FP.PostedFile.SaveAs(Server.MapPath(path) + fName); //path 包含 "/"
return fName;
}
catch (Exception ex) {throw new Exception("上传文件时出错,"+ex.Message);}
}
private bool isCurFile(string fty)
{
string[] fstr = this.fileStr.Trim().Split('|');
for (int i=0;i<fstr.Length;i++)
{
if (fstr[i] == fty)
return true;
}
return false;
}
private void cfrFile(string f)
{
//string sf = Server.MapPath(f);
if(!Directory.Exists(f))
{
Directory.CreateDirectory(f);
}
}
public bool IsNumber(string str)
{
try {
Convert.ToDouble(str);
return true;
} catch(Exception ex) {
return false;
}
}
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -