码迷,mamicode.com
首页 > 其他好文 > 详细

jq表单上传多文件 前后台代码

时间:2014-08-06 18:35:11      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   http   java   os   io   strong   文件   for   

Html>>>>>>>>>

  <form id="Job_Notice_Form"  method="post" enctype="multipart/form-data">

<div id="f" >
<div id="zhi"> <div style="display:none">
<div id="content">
<input id="File1" type="file" name="file" style=" width:450px;" />&nbsp;
<a id="jian" href="#" class="easyui-linkbutton" data-options="iconCls:‘icon-delete‘">删除</a>
<br />
</div>
</div>
</div>
</div>
<a id="tianjia" href="#" class="easyui-linkbutton" data-options="iconCls:‘icon-add‘">添加</a>

<a id="tianjia" href="#" class="easyui-linkbutton" onclik="Save()" data-options="iconCls:‘icon-Save‘">保存</a>

 

</form>

JS>>>>>>

<script type="text/javascript">
$(function () {
//跟添加按钮绑定点击事件
$("#tianjia").bind("click", function () {
//克隆id=content下面的元素。添加到id=zhi的div里面
$("#content").clone(true).appendTo("#zhi");

});

//删除file控件操作
$("#jian").click(function () {
//查找上传控件的个数
var shu = $("#zhi").find("#content").size();
//如果有多,就删除掉

$(this).parent().remove();

});
});
function DelFile(id) {
$("#zhi").append(‘ <input name="DelFile" value="‘ + id + ‘" type="hidden" />‘)

}

 

funtion Save()

{

//----上传文件

top.$("#Job_Notice_Form").form(‘submit‘, {
url: "/View/Admin/App/Ashx/Job_File_Handler.ashx?action=add",
onSubmit: function () {

},
success: function (data) {
var d = eval(‘(‘ + data + ‘)‘);
if (d.Success) {
var i = d.Data;
alert(d.Data);

}
else {
msg.warning(data.Message);
}

}
})

 


//-End-上传文件

}
</script>

后台》》》》》》

string action = context.Request["action"];
switch (action)
{

case "add":
string FileIdSet = "";

if (context.Request.Files.Count > 0)
{

for (int i = 0; i < context.Request.Files.Count; i++)
{

Job_File file = new Job_File();
HttpPostedFile hpFile = context.Request.Files[i];
if (!String.IsNullOrEmpty(hpFile.FileName))
{
string ext = System.IO.Path.GetExtension(hpFile.FileName);
if (hpFile.ContentType != "image/jpeg" || hpFile.ContentType != "image/pjpeg")
{

file.FileType = 1;
//给文件取随及名
Random ran = new Random();
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(100, 1000) + ext;
//保存文件
string path = context.Request.MapPath(fileName);
file.FileName = hpFile.FileName.Substring(hpFile.FileName.LastIndexOf("\\") + 1);
string uriString = System.Web.HttpContext.Current.Server.MapPath("~/View/UpLoad/App/").ToString();
file.FilePath = "/View/UpLoad/App/" + path.Substring(path.LastIndexOf("\\") + 1);
hpFile.SaveAs(uriString + file.FilePath.Substring(file.FilePath.LastIndexOf("/") + 1));
//提示上传成功
}

/*添加一条信息;*/
int res = Job_File_DAL.Instance.Insert(file);
FileIdSet += res + ",";
}
}
}

if (!String.IsNullOrEmpty(FileIdSet))
{
JsonMsg = new JsonMessage
{
Success = true,
Data = FileIdSet.Substring(0, FileIdSet.Length-1),
Message = "添加成功"
}.ToString();
}
else
{
JsonMsg = new JsonMessage
{
Success = false,
Data = "0",
Message = "添加失败"
}.ToString();
} context.Response.Write(JsonMsg);
context.Response.End();
break;}

jq表单上传多文件 前后台代码,布布扣,bubuko.com

jq表单上传多文件 前后台代码

标签:style   http   java   os   io   strong   文件   for   

原文地址:http://www.cnblogs.com/lucoo/p/3895197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!