天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMAPP.Common.Web.Controllers;
using System.Text;
using System.Text.RegularExpressions;
namespace QMAPP.MD.Web.Controllers
{
public class ImageController : QController
{
#region 上传文件
/// <summary>
/// 载入行为
/// </summary>
/// <returns></returns>
public ActionResult ImageUplod()
{
return View();
}
/// <summary>
/// 上传行为
/// </summary>
/// <param name="file">文件</param>
/// <returns>js</returns>
[HttpPost]
public ActionResult ImageUplod(HttpPostedFileBase file)
{
string expandName = "";
string fileName = file.FileName;
try
{
//构造文件名
if (fileName.IndexOf(".") > 0)
{
//文件格式后缀
expandName = fileName.Substring(fileName.LastIndexOf(".") + 1);
}
// 设置完整(文件名+文件格式)
fileName = Guid.NewGuid().ToString() + "." + expandName;
string imagePath = System.Configuration.ConfigurationManager.AppSettings["ImagePath"].ToString();
//string imagePath = "Images/MaterialImage/"; // 获取保存图片的项目文件夹
string uploadPath = Server.MapPath("~/" + imagePath); // 将项目路径与文件夹合并
//保存文件
string savePath = uploadPath + fileName;
file.SaveAs(savePath);
return this.GetJsViewResult(string.Format("window.returnValue='{0}';window.close();", System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8)));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}