不需要用到数据库!只是上传后显示图片,我试了FileUpload但是不成功……
在asp.net中怎样上传照片?用什么控件?
- 提问者网友:niaiwoma
- 2021-04-24 03:49
- 五星知识达人网友:春色三分
- 2021-04-24 04:01
图片:<asp:FileUpload ID="FileUpload1" runat="server" />
后台代码
string savePath = @"UploadFiles/";
string savePath1 = @"UploadFiles/smaill/";
string fileName = Server.HtmlEncode(FileUpload1.FileName);
string extension = System.IO.Path.GetExtension(fileName);
string ImageName = null;
if ((extension == ".jpg") | (extension == ".gif"))
{
ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + extension;
savePath += ImageName;
savePath1 += ImageName;
savePath = Server.MapPath(savePath);
savePath1 = Server.MapPath(savePath1);
FileUpload1.SaveAs(savePath);
//生成小图 ,这里用到个其他类 可以不用 我注释调了
//ImageClass.ImageClass imageClass = new ImageClass.ImageClass();
//imageClass.ShowThumbnail(savePath, savePath1, 200, 153);
}
else
{
Response.Write("<script>alert('文件上传格式错误');history.back(1);</script>");
Response.End();
}
- 1楼网友:詩光轨車
- 2021-04-24 06:08
FileUpload控件
- 2楼网友:末日狂欢
- 2021-04-24 04:57