我有一个用于个人资料图片上传的 AJAX 文件上传器。我想限制用户仅上传最多 102400 字节的图像。文件大小超过时如何显示 javascript 错误消息。
代码:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string workerfile = Session["LoginUserID"].ToString();
string strFileName = string.Empty;
string strFileType = string.Empty;
string path = string.Empty;
var folder = Server.MapPath("../worker/Uploads/" + workerfile);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
strFileName = DateTime.Now.ToString("MM-dd-yyyy_HHmmss");
strFileType = System.IO.Path.GetExtension(e.FileName).ToString().ToLower();
AjaxFileUpload1.SaveAs(Server.MapPath("../worker/Uploads/" + Session["LoginUserID"] + "/" + workerfile + "_img" + strFileType));
}
else
{
strFileName = DateTime.Now.ToString("MM-dd-yyyy_HHmmss");
strFileType = System.IO.Path.GetExtension(e.FileName).ToString().ToLower();
AjaxFileUpload1.SaveAs(Server.MapPath("../worker/Uploads/" + Session["LoginUserID"] + "/" + workerfile + "_img" + strFileType));
}
}
如何做任何想法?帮助赞赏。