mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
check issue #26
This commit is contained in:
parent
efbb69cc1f
commit
3f5eece334
75
OpenAuth.Mvc/Areas/FlowManage/Controllers/FileController.cs
Normal file
75
OpenAuth.Mvc/Areas/FlowManage/Controllers/FileController.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1371,8 +1371,8 @@ $.fn.frmPreview = function (options)
|
|||||||
function fuploadify(control_field,btnName) {
|
function fuploadify(control_field,btnName) {
|
||||||
$("#" + control_field).uploadify({
|
$("#" + control_field).uploadify({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
uploader: '/FlowManage/FormDesign/UploadifyFile',
|
uploader: '/FlowManage/File/Upload',
|
||||||
swf: top.contentPath + '/Content/scripts/plugins/uploadify/uploadify.swf',
|
swf: '/Content/scripts/plugins/uploadify/uploadify.swf',
|
||||||
buttonText: btnName,
|
buttonText: btnName,
|
||||||
height: 30,
|
height: 30,
|
||||||
width: 90,
|
width: 90,
|
||||||
|
@ -142,6 +142,7 @@
|
|||||||
<Compile Include="App_Start\BundleConfig.cs" />
|
<Compile Include="App_Start\BundleConfig.cs" />
|
||||||
<Compile Include="App_Start\FilterConfig.cs" />
|
<Compile Include="App_Start\FilterConfig.cs" />
|
||||||
<Compile Include="App_Start\RouteConfig.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\FormDesignController.cs" />
|
||||||
<Compile Include="Areas\FlowManage\Controllers\FlowDesignController.cs" />
|
<Compile Include="Areas\FlowManage\Controllers\FlowDesignController.cs" />
|
||||||
<Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" />
|
<Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user