zoukankan      html  css  js  c++  java
  • 文件流上传图片

    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 "";
    }
    }

  • 相关阅读:
    yii2.0 干货
    VLD opcodes 在线查看
    定长顺序串的实现
    循环队列
    oracle--DG初始化参数
    oracle --工具 ODU
    Oracle RAC 修改SPFILE路径 文件查看
    oracle 错误 ORA-00020问题解析
    oracle 错误 TNS-01190与oracle 登入没反应操作
    Oracle--RMAN Recover 缺失的归档操作
  • 原文地址:https://www.cnblogs.com/mingdep/p/5190210.html
Copyright © 2011-2022 走看看