打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
做论坛其实并不难,只要你掌握了几句精华的asp语法,就能搞定。
<system.web>
<httpRuntime executionTimeout="300" maxRequestLength="204800" useFullyQualifiedRedirectUrl="false"/>
</system.web>
C#
if (FuPhoto.HasFile)
{
string fileContentType = FuPhoto.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")
{
string name = FuPhoto.PostedFile.FileName; // 客户端文件路径
FileInfo file = new FileInfo(name);
// 缩略图文件名称
string fileName_s = DateTime.Now.ToString("yyyyMMddHHmmssS") + file.Name;
// 服务器端文件路径
string webFilePath_s = Server.MapPath("../UploadBlogPhoto/" + userID + "/" + fileName_s);
string strCreatPath = "../UploadBlogPhoto/" + userID;
if (!File.Exists(webFilePath_s))
{
try
{
if (FuPhoto.PostedFile.ContentLength > 2048000)
{
Jscript.Alert("提示:上传图片大小不能超过2048K");
// Response.Write("<script language='JavaScript'>alert('上传图片大小不能超过2048K'):history.go(-1);</script>");
return;
}
if (Directory.Exists(Server.MapPath(strCreatPath)) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(Server.MapPath(strCreatPath));
}
FuPhoto.SaveAs(webFilePath_s); // 使用 SaveAs 方法保存文件
          //model PiUrl属性字段
bumodel.PicUrl = "/UploadBlogPhoto/" + userID + "/" + fileName_s;//压缩过的图片
          //保存方法
buBll.Add(bumodel);//添加相片
Response.Write("<script language='JavaScript'>alert('添加相片成功');window.location='BlogUserPic.aspx?userID=" + userID + "';</script>");
Response.End();
}
catch (Exception ex)
{
Jscript.Alert("提示:相片上传失败,失败原因:" + ex.Message);
}
}
else
{
Jscript.Alert("提示:相片已经存在,请重命名后上传");
}
}
else
{
Jscript.Alert("提示:相片类型不符");

}
}
 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
让ASP.NET的FileUpload控件支持浏览自动上传功能
上传图片检测其是否为真实的图片 防范病毒上传至服务器
ASP.NET FileUpload应用实例
fileupload用法 - qingtiansunsky的日志 - 网易博客
html form表单提交数据并后台获取
FileUpload文件上传代码
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服