//一般处理程序
public void GetImageFromWeb()
{ //创建文件夹 //2016-10-14 dq
string filePath = "~/ProductImage/";
string mapFilePath;
mapFilePath = HttpContext.Current.Server.MapPath(filePath);
if (!Directory.Exists(mapFilePath))
{
Directory.CreateDirectory(mapFilePath);
}
filePath += userEntity.User_ID + "/";
mapFilePath = HttpContext.Current.Server.MapPath(filePath);
if (!Directory.Exists(mapFilePath))
{
Directory.CreateDirectory(mapFilePath);
}
//2016-10-14 注释 dq //写入数据库的路径
string imgUrl = "/ProductImage/" + userEntity.User_ID + "/"; // 图片数据 HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
string fileName = files[].FileName;
string name = System.IO.Path.GetFileName(fileName);
Stream stream = files[].InputStream;
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, , bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(, SeekOrigin.Begin);
ResImgUpLoadData entity = WS.UploadImgs(bytes, mapFilePath, name, imgUrl, userEntity); BaseReturn(entity); }
//C#代码
#region 图片上传
/// <summary>
// 功能简述:接口公开方法,图片上传
// 开发文档:无
// 开发团队:新产品组
// 设计:邓
// 分析:邓
// 代码:邓
// 开发时间:2016.3.10
// 代码检查:
// 是否在使用:是
/// <summary>
/// 上传图片
/// </summary>
/// <param name="bytes">图片信息</param>
/// <param name="pFileName">文件夹名称</param>
/// <param name="pImgName">图片名称</param>
/// <param name="pImgPath">写入数据库的图片路径</param>
/// <param name="pUserInfo">操作人</param>
/// <returns></returns>
/// public ProductOnShelvesDML.ResImgUpLoadData UploadImgs(byte[] bytes, string pFileName, string pImgName, string pImgPath, UserDML.UserLoginInfo pUserInfo)
{
return pUploadImgs(bytes, pFileName,pImgName, pImgPath,pUserInfo);
} private ProductOnShelvesDML.ResImgUpLoadData pUploadImgs(byte[] bytes,string pFileName,string pImgName, string pImgPath,UserDML.UserLoginInfo pUserInfo)
{
ProductOnShelvesDML.ResImgUpLoadData objResult=new ProductOnShelvesDML.ResImgUpLoadData();
//V_User_DB_Info objUserDBRes;
//PublicCommonDML.ResComm objResComm;
//Common objCommonDB; //objResult = new ProductOnShelvesDML.ResImgUpLoadData();
//objCommonDB = new Common();
Common objCommonDB = new Common();
PublicCommonDML.ResComm objResComm = new PublicCommonDML.ResComm(); ; try
{
string CommomString = "";//保存连接实体String
// 验证用户信息,并获得连接实体
// 代码:邓奇
// 开发时间:2016-10-17
SYSCEntityDBAddLogic objSYSCEntityDBAddLogic = new SYSCEntityDBAddLogic();
objResComm = objSYSCEntityDBAddLogic.GetUserDBString(pUserInfo.User_ID, pUserInfo.User_PWD);
if (objResComm.ResState == PublicCommonDML.ResFlag.Success)
{
CommomString = objSYSCEntityDBAddLogic.ConectionSring;
}
else
{
objResult.ResComm = objResComm;
return objResult;
} //服务器端创建文件夹并保存在WS端 //string filePath = "myImg";
//string mapFilePath;
//mapFilePath = HttpContext.Current.Server.MapPath(filePath);
//if (!Directory.Exists(mapFilePath))
// Directory.CreateDirectory(mapFilePath);
//filePath += pUserInfo.User_ID + "/";
//mapFilePath = HttpContext.Current.Server.MapPath(filePath);
//if (!Directory.Exists(mapFilePath))
// Directory.CreateDirectory(mapFilePath);
//filePath += pUserInfo.User_ID + "/";
//mapFilePath = HttpContext.Current.Server.MapPath(filePath);
//if (!Directory.Exists(mapFilePath))
// Directory.CreateDirectory(mapFilePath);
// 图片数据
//Stream stream = new MemoryStream(bytes);//数据转换
//MemoryStream ms = new MemoryStream();
//System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
//img.Save(pFileName + pImgName);//保存
//ms.Close();
//string path = mapFilePath + pImgName;
//objResult.ResComm.ResState = PublicCommonDML.ResFlag.Success;
//objResult.ResComm.ResMessage = path;//返回图片路径
//return objResult; ////pFileName-----不需从前端传进,由配置文件设置
//string PhysicalAddress = System.Configuration.ConfigurationSettings.AppSettings["PhysicalAddress"];//存放图片的物理位置以及名称
//pFileName = @PhysicalAddress;
//pFileName += pUserInfo.User_ID + "\\";
//if (!Directory.Exists(pFileName))
//{
// Directory.CreateDirectory(pFileName);//创建文件夹
//}
//string IPAddress = System.Configuration.ConfigurationSettings.AppSettings["IPAddress"];//存放图片的物理位置对应的项目IP //创建文件夹(在一般处理程序完成)并保存在WEB端 //限制图片格式
bool Isimage = false;
string suff = pImgName.Substring(pImgName.LastIndexOf('.'), pImgName.Length - pImgName.LastIndexOf('.')); //获取文件后缀
string[] allowExtension = { ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".JPG", ".JPEG", ".GIF", ".BMP", ".PNG" };
for (int i = ; i < allowExtension.Length; i++)
{
if (suff == allowExtension[i])
{
Isimage = true;
break;
}
else
{ Isimage = false; }
}
if (!Isimage)
{
objResult.ResComm.ResState = PublicCommonDML.ResFlag.Fail;
objResult.ResComm.ResMessage = "图片格式不正确,上传失败";
return objResult;
} // 图片数据
Stream stream = new MemoryStream(bytes);//数据转换
if (stream.Length > ) //1M
{
objResult.ResComm.ResState = PublicCommonDML.ResFlag.Fail;
objResult.ResComm.ResMessage = "图片大小超过1M,上传失败";
return objResult;
}
else
{
MemoryStream ms = new MemoryStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
string imgName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + suff; //图片名称
img.Save(pFileName + imgName);//保存
ms.Close(); string path = pFileName + imgName;//图片全路径
objResult.ResComm.ResState = PublicCommonDML.ResFlag.Success;
objResult.img_url = pImgPath+imgName;//返回图片相对路径
objResult.ResComm.ResMessage = "上传成功";
} return objResult; }
catch (Exception ex)
{
string strMsg;
string strErrMsg;
strMsg = pUserInfo.User_ID + "\r\n" + pUserInfo.User_PWD + "\r\n" + ACCPCWS.MyCommons.Common.DMLToXML(pImgName.GetType(), pImgName);
strErrMsg = LogLogic.WriteLog(ex, "E100008", strMsg);
if (strErrMsg == "")
{
objResult.ResComm.ResState = PublicCommonDML.ResFlag.Error;
objResult.ResComm.ResMessage = "系统服务器维护中,请稍后重试。";
}
else
{
objResult.ResComm.ResState = PublicCommonDML.ResFlag.SysErrorMsg;
objResult.ResComm.ResMessage = strErrMsg;
}
} return objResult;
} #endregion

最新文章

  1. Oracle 数据库基础学习 (七) SQL语句综合练习
  2. python第一天基础1-1
  3. SOLID面向对象的五个设计原则,留空待学习。
  4. 借助阿里AntUI元素实现两个Web页面之间的过渡——“Loading…”
  5. Winform在一个窗体获取其他窗体的值
  6. 屌丝IT男
  7. 10个有关RESTful API良好设计的最佳实践(转)
  8. C/C++笔试题整理
  9. crm操作观点
  10. innodb系统表空间维护
  11. PHP设计模式概述
  12. python类与对象-如何创建可管理的对象属性
  13. 01_新建WebApi后端服务项目
  14. expect 自动化控制命令
  15. Hdoj 1879.继续畅通工程 题解
  16. 面试官问我,使用Dubbo有没有遇到一些坑?我笑了
  17. Connections in Galaxy War (逆向并查集)题解
  18. Python编写类似nmap的扫描工具
  19. Ulipad安装、配置使用教程(附Ulipad下载)
  20. Caused by: java.lang.IllegalArgumentException: Can not set int field reyo.sdk.enity.xxx.xxx to java.lang.Long

热门文章

  1. ThinkPHP 多语言
  2. Junit的使用
  3. 小猪cms ClassifyAction.class.php
  4. ThinkPhp 3.2 CRUD操作
  5. Mac安装mysql
  6. 博文Contents&lt;1--到200—&gt;
  7. 苹果iphone手机上input的button按钮颜色显示有问题,安卓却没问题
  8. Fedora20-64bit cross-compiling arm-linux-gcc
  9. 盒子 offsetLeft、offsetTop、offsetWidth、getBoundingClientRect等属性解释
  10. Velocity 局部定制模板