easyui上次图片
easyuiForm提交:
前台代码:
<form id="importFileForm" method="post" enctype="multipart/form-data" style="display:">
<table style="margin:5px;height:70px;">
<tr>
<td></td>
<td width="5px;"></td>
<td><input class="easyui-filebox" id="fileImport" data-options="buttonText:'选择',prompt:'请选择文件...'" name="fileImport" style="width:260px;">
</td>
<td><a id="uploadFile" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)">上传</a></td>
</tr>
<tr>
<td colspan="4">
<label id="uploadInfo" />
</td>
</tr>
</table>
</form>
<script>
//导入文件
$("#uploadFile").click(function () {
var formData = new FormData($("#importFileForm")[0]);
//调用apicontroller后台action方法,将form数据传递给后台处理。contentType必须设置为false,否则chrome和firefox不兼容
$.ajax({
url: "http://localhost:12745/api/easyuiUpload/PostExcelData",
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returnInfo) {
//上传成功后将控件内容清空,并显示上传成功信息
document.getElementById('fileImport').value = null;
document.getElementById('uploadInfo').innerHTML = "<span style='color:Red'>" + returnInfo + "</span>";
},
error: function (returnInfo) {
//上传失败时显示上传失败信息
document.getElementById('uploadInfo').innerHTML = "<span style='color:Red'>" + returnInfo + "</span>";
}
}); })
</script>
后台代码:
[HttpPost]
public string PostExcelData()
{
string info = string.Empty;
try
{
//获取客户端上传的文件集合
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
//判断是否存在文件
if (files.Count > 0)
{
//获取文件集合中的第一个文件(每次只上传一个文件)
HttpPostedFile file = files[0];
//定义文件存放的目标路径
string targetDir = System.Web.HttpContext.Current.Server.MapPath("~/FileUpLoad/Product");
//创建目标路径
if (!Directory.Exists(targetDir))
{
Directory.CreateDirectory(targetDir);
}
//ZFiles.CreateDirectory(targetDir);
//组合成文件的完整路径
string path = System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(file.FileName));
//保存上传的文件到指定路径中
file.SaveAs(path);
info = "上传成功";
}
else
{
info = "上传失败";
}
}
catch
{
info = "上传失败";
}
return info;
}
easyui另类Form提交(前台页不需要form表单):
前台代码:
<script type="text/javascript">
$.support.cors = true;
var ApiUrl = "http://localhost:12745/";
$(function () {
$("#upload").click(function () {
$("#imgWait").show();
var formData = new FormData();
formData.append("myfile", $("#file1").next().find('input[id^="filebox_file_id_"]')[0].files[0]);
formData.append("myfile2", $("#file2").next().find('input[id^="filebox_file_id_"]')[0].files[0]);
$.ajax({
url: ApiUrl + "api/FileManage/UploadFile",
type: "POST",
data: formData,
/**
*必须false才会自动加上正确的Content-Type
*/
contentType: false,
/**
* 必须false才会避开jQuery对 formdata 的默认处理
* XMLHttpRequest会对 formdata 进行正确的处理
*/
processData: false,
success: function (data) {
if (data.status == "true") {
alert("上传成功!");
}
if (data.status == "error") {
alert(data.msg);
}
$("#imgWait").hide();
},
error: function () {
alert("上传失败!");
$("#imgWait").hide();
}
});
});
});
</script>
</head>
<body>
<!--选择文件:<input type="file" id="file1" /><br />-->
<input class="easyui-filebox" id="file1" data-options="prompt:'Choose another file...'" style="width:150px">
<input class="easyui-filebox" id="file2" data-options="prompt:'Choose another file...'" style="width:150px">
<input type="button" id="upload" value="上传" />
<img src="wait.gif" style="display:none" id="imgWait" />
</body>
后台代码:
[HttpPost]
public HttpResponseMessage UploadFile()
{
HttpResponseMessage result = null;
var httpRequest = System.Web.HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
try
{
string url = string.Empty;
foreach (string file in httpRequest.Files)
{ var postedFile = httpRequest.Files[file];
var filePath = System.Web.HttpContext.Current.Server.MapPath("~/Files/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
postedFile.SaveAs(filePath + postedFile.FileName);
url += "Files/" + postedFile.FileName + ",";
} result = Request.CreateResponse(HttpStatusCode.OK, url.Substring(0, url.Length - 1)); }
catch (Exception ex)
{
result = Request.CreateResponse(HttpStatusCode.OK, "error:" + ex.Message);
} }
else
{
result = Request.CreateResponse(HttpStatusCode.OK, "0");
}
return result;
}
easyui上次图片的更多相关文章
- EasyUI实现图片的上传后与其他文本框的提交以及DataGrid中图片的展示
图片即文件,在jsp中文件上传很简单,一个type为file的input,一个form指定enctype为multipart/form-data,通过post提交到后台利用apache的commons ...
- easyui多图片上传+预览切换+支持IE8
引入css和js: <link href="${pageContext.request.contextPath}/plugin/dialog/dialog.css" rel= ...
- asp:FileUpload 上次图片
<asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" /> ...
- C#--图片上传(PC端和APP)保存及 跨域上传说明
手动跨域操作文件 补录:跨域访问文件夹文件是一种常见的需求,下面主要介绍的的通过代码使用具有权限账号的人来达到跨域操作文件的能力. 现在补充一下普通的一些需求场景,今天就遇到了一种需要经常需要登录远程 ...
- SSM后台管理系统(Spring SpringMVC Mybatis Mysql EasyUI)
非常简单的一个后台管理系统,功能不多,框架也不复杂, 源码下载(附数据库)-ssm后台管理系统框架(Spring mvc + mybatis + mysql + easyui ) 实例图片
- EasyUI之Layout布局和Tabs页签的使用
1.JQuery EasyUI之LayOut布局 EasyUI是一款基于JQuery开发的前端框架,它集成很多漂亮的样式和相应的功能,大大方便了我们对前端开发的难度.对于web项目而言,主页面的一定是 ...
- php,session验证码不一致慢半拍
这种问题遇到过一次,后来忘了怎么解决了,所以做下笔记 输出的$_SESSION['code']之所以比图片慢了‘一帧’,这也纯属正常情况因为输出的图片是一个连接一次调用,而echo $_SESSION ...
- node.js之十大Web框架
之前接触过Node.js是因为好奇大前端越来越能干了,连我后台的饭碗都要抢了,太嚣张了,于是我想打压打压它,然后就这样接触它了.再到后来是因为Settings-Sync插件二次开发,我需要用node. ...
- Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
使用 HTML5 的图片上传api的时候报如下错误: Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLIn ...
随机推荐
- 转:sock_ev——linux平台socket事件框架(uri地址的解析) .
在第一篇中,已经说明,传递的socket地址采取以下形式: [cpp] view plaincopyprint?stream://192.168.2.10:8080 dgram://192.168 ...
- tp类型自动转换和自动完成
一.类型自动转换 在模型中对数据库字段自动完成 //模型中数据类型自动转换 添加一个$type数组即可protected $type=array( 'username'=>'serialize' ...
- AHK GUI开发示例
GUI.AHK Gui, Add, Text, gAllSearchA W120, 搜索引擎类: Gui, Add, Checkbox, gMySubroutine Checked HwndMyEdi ...
- Android系统应用信息中存储和缓存的计算方法
进行例如以下操作: 设置->应用->选择一个应用->应用信息 会到达例如以下界面: 能够看到这个应用占用的磁盘空间. 先说结果,这几项会计算哪些文件(夹). 1.应用,由三项相加组成 ...
- Spring3的表达式语言
Spring表达式语言全称为“Spring Expression Language”,缩写为“SpEL”,类似于Struts2x中使用的OGNL表达式语言, 能在运行时构建复杂表达式.存取对象图属性. ...
- 基于HTML5 Canvas生成粒子效果的人物头像
前面我们分享过一个HTML5 Canvas实现的图像马赛克模糊效果,HTML5处理图片真的非常简单.今天我们要再利用HTML5 Canvas实现一个粒子效果的人物头像,你可以任意选择一张头像图片,接下 ...
- 一款基于jQuery带事件记录的日历插件
之前我们也已经分享过不少jQuery日历插件,有些应用了CSS3的特性,外观就特别漂亮.今天要分享的这款jQuery日历插件不仅有着绚丽的外观,而且带有日期事件记录功能,点击日期即可展开事件记录窗口, ...
- 一题关于PHP的CTF
if(isset($_GET['time'])){ if(!is_numeric($_GET['time'])){ echo 'The time must be number.'; }else if( ...
- Unix系统编程()改变信号处置:signal
Unix系统提供了两种方法来改变信号处置:signal和sigaction.这篇描述的是signal系统调用,是设置信号处理的原始API,所提供的接口比sigaction简单.另一方面,sigacti ...
- [Linux]gcc/libc/glibc
转自:http://blog.csdn.net/weiwangchao_/article/details/16989713 1.gcc(gnu collect compiler)是一组编译工具的总称. ...