check issue #26

This commit is contained in:
yubaolee 2017-03-06 17:02:50 +08:00
parent efbb69cc1f
commit 3f5eece334
3 changed files with 78 additions and 2 deletions

View File

@ -0,0 +1,75 @@
using System;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.Mvc.Controllers;
namespace OpenAuth.Mvc.Areas.FlowManage.Controllers
{
public class FileController : BaseController
{
[HttpPost]
public string Upload(HttpPostedFileBase Filedata)
{
if (Filedata != null && Filedata.ContentLength > 0 && Filedata.ContentLength < 10485760)
{
using (var binaryReader = new BinaryReader(Filedata.InputStream))
{
var fileName = Path.GetFileName(Filedata.FileName);
var data = binaryReader.ReadBytes(Filedata.ContentLength);
var result = UploadFile(fileName, data, string.Empty);
Result.Result = result;
}
}
else
{
Result.Message = "文件过大";
Result.Status = false;
}
return JsonHelper.Instance.Serialize(Result);
}
public string UploadFile(string fileName, byte[] fileBuffers, string folder)
{
if (string.IsNullOrEmpty(folder))
{
folder = DateTime.Now.ToString("yyyy_MM_dd");
}
//判断文件是否为空
if (string.IsNullOrEmpty(fileName))
{
throw new Exception("文件名不能为空");
}
//判断文件是否为空
if (fileBuffers.Length < 1)
{
throw new Exception("文件不能为空");
}
var filePath =Server.MapPath("upload");
var uploadPath = filePath +"\\" + folder + "\\";
var ext = Path.GetExtension(fileName);
var newName = Guid.NewGuid().ToString("N") + ext;
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
using (var fs = new FileStream(uploadPath + newName, FileMode.Create))
{
fs.Write(fileBuffers, 0, fileBuffers.Length);
fs.Close();
return folder + "/" + newName;
}
}
}
}

View File

@ -1371,8 +1371,8 @@ $.fn.frmPreview = function (options)
function fuploadify(control_field,btnName) {
$("#" + control_field).uploadify({
method: 'post',
uploader: '/FlowManage/FormDesign/UploadifyFile',
swf: top.contentPath + '/Content/scripts/plugins/uploadify/uploadify.swf',
uploader: '/FlowManage/File/Upload',
swf: '/Content/scripts/plugins/uploadify/uploadify.swf',
buttonText: btnName,
height: 30,
width: 90,

View File

@ -142,6 +142,7 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Areas\FlowManage\Controllers\FileController.cs" />
<Compile Include="Areas\FlowManage\Controllers\FormDesignController.cs" />
<Compile Include="Areas\FlowManage\Controllers\FlowDesignController.cs" />
<Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" />