首页 > Web开发 > 详细

文件流上传图片

时间:2016-02-15 12:16:39      阅读:167      评论:0      收藏:0      [点我收藏+]

public string SeveImage(string hpf, out string imgaddr)
{


bool isSavedSuccessfully = true;
string fileName = string.Empty;
string fileNames = string.Empty;
try
{
byte[] arr = Convert.FromBase64String(hpf);

MemoryStream ms = new MemoryStream(arr);
Bitmap bmp = new Bitmap(ms);
string dirpath = string.Empty;

dirpath = HttpContext.Current.Server.MapPath("/") + @"/uploadimages/Appeal/";
//var fileName = ImgSavePath + Path.GetRandomFileName() + Path.GetExtension(file.FileName);


if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
//string path = Guid.NewGuid().ToString() + ".Gif";//文件名
string path = Path.GetRandomFileName() + ".png";//文件名
fileName = path;

fileNames = dirpath + fileName; //路径
bmp.Save(fileNames, System.Drawing.Imaging.ImageFormat.Png);
}
catch (Exception ex)
{
log4net.LogManager.GetLogger("AccessTxt").Info("______意见建议保存图片SeveImage方法" + ex.ToString());
isSavedSuccessfully = false;
}

if (isSavedSuccessfully)
{
imgaddr = @"/uploadimages/Appeal/" + fileName; ;
//return GetWebConfig.GetWebKeyValue("upImageIp") + @"/uploadimages/"+ fileName;
return @"/uploadimages/" + fileName;
}
else
{
imgaddr = "";
return "";
}
}

文件流上传图片

原文:http://www.cnblogs.com/mingdep/p/5190210.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!