当前位置: 移动技术网 > IT编程>网页制作>CSS > 基于WebUploader的图片上传解析

基于WebUploader的图片上传解析

2018年09月19日  | 移动技术网IT编程  | 我要评论
基于webuploader的图片上传 uploadcontroller.cs using system; using system.collections.generic; using system

基于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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网