基于WebUploader的图片上传解析
基于webuploader的图片上传
uploadcontroller.cs
using system;
using system.collections.generic;
using system.io;
using system.linq;
using system.web;
using system.web.m;
namespace webapplication.controllers
{
///
/// 基于webuploader插件的图片上传实例
///
public class uploadcontroller : controller
{
// get: upload
public actionresult index()
{
return view();
}
///
/// 直接上传
///
///
public actionresult upload()
{
return view();
}
///
/// 简单上传
///
///
public actionresult simpleupload()
{
return view();
}
///
/// 模态框上传
///
///
public actionresult modalupload()
{
return view();
}
///
/// 上传文件方法
///
///表单参数
///文件
///
[httppost]
public actionresult uploadimg(formcollection form, httppostedfilebase file)
{
try
{
string filepathname = string.empty;
string localpath = string.empty;
string imagepath = string.empty;
imagepath = "/upload/images/user/";
localpath = path.combine(httpruntime.appdomainapppath, "upload/images/");
if (request.files.count == 0)
{
throw new exception("请选择上传文件!");
//return json(new jsonresultmodel(-1,"请选择上传文件",null));
}
string ex = path.getextension(file.filename);
filepathname = guid.newguid().tostring("n") + ex;
if (!system.io.directory.exists(localpath))
{
system.io.directory.createdirectory(localpath);
}
file.saveas(path.combine(localpath, filepathname));
// string imgaddress = request.url.getleftpart(uripartial.authority) + imagepath + filepathname;
string imgaddress = imagepath + filepathname;
return json(new
{
status = 200,
message = "上传图片成功!",
data = imgaddress
});
}
catch (exception)
{
//扔出异常
throw;
}
}
}
}
upload.cshtml
@{
viewbag.title = "webuploader上传实例";
layout = "~/views/shared/_layout.cshtml";
}
或将照片拖到这里,并支持截图粘贴功能
0%
开始上传
simpleupload.cshtml
@{
viewbag.title = "webuploader上传实例";
layout = "~/views/shared/_layout.cshtml";
}
图片地址
上传图片
@*上传图片*@
modalupload.cshtml
@{
viewbag.title = "modalupload";
layout = "~/views/shared/_layout.cshtml";
}
×
上传图片
或将照片拖到这里,并支持截图粘贴功能
0%
开始上传
上传图片
_layout.cshtml
@**@
首页 直接上传 简单上传 模态框上传
@renderbody()
© @datetime.now.year - my asp.net application
上一篇: Bootstrap插件设计之Tooltip插件解析
下一篇: php实现单笔转账到支付宝功能