zoukankan      html  css  js  c++  java
  • 服务器端接收移动端上传的图片

    移动端项目如安卓和苹果应用,有时候移动端有上传图片的功能。在做手机接口的时候怎么接收这些图片呢?

                var dat = DateTime.Now;
    for (int i = 0; i < HttpContext.Current.Request.Files.Count; /*多图片*/ i++) { string fname = ""; string saveUrl = string.Format("/upload/mobile/{0}/{1}/{2}/", dat.Year, dat.Month, dat.Day); if (!Directory.Exists(Server.MapPath(saveUrl))) //判断路径是否存 Directory.CreateDirectory(Server.MapPath(saveUrl)); //不存在创建目录 HttpPostedFile file = HttpContext.Current.Request.Files[i]; fname = saveUrl + file.FileName; file.SaveAs(Server.MapPath(fname)); //保存图片 }

    有时候客户希望显示图片的时候能够按照客户上传图片来显示怎么办呢?那么图片保存进数据库的时候要做一个排序。

    
    
                 var dat = DateTime.Now;
    var spliContent = string.Empty; //图片先拼装 for (int i = 0; i < HttpContext.Current.Request.Files.Count; /*多图片*/ i++) { string fname = ""; string saveUrl = string.Format("/upload/mobile/{0}/{1}/{2}/", dat.Year, dat.Month, dat.Day); if (!Directory.Exists(Server.MapPath(saveUrl))) //判断路径是否存 Directory.CreateDirectory(Server.MapPath(saveUrl)); //不存在创建目录 HttpPostedFile file = HttpContext.Current.Request.Files[i]; fname = saveUrl + file.FileName; file.SaveAs(Server.MapPath(fname)); //保存图片

    if (!string.IsNullOrEmpty(fname))
                    {
                        spliContent += "|" + fname;
                    }
    }

    if (HttpContext.Current.Request.Files.Count >0) { string[] arrs = spliContent.Split('|'); List<string> Arrslist = arrs.ToList(); Arrslist.Sort();//注意泛型才有排序的方法 for (int i = 0; i < arrs.Length; i++) { if (!string.IsNullOrEmpty(Arrslist[i])) Arrslist[i];//可以保存的数据库的文件名,可以加上路径 } }
  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/yopo/p/8134346.html
Copyright © 2011-2022 走看看