flash上传附件
<script src="../../../Scripts/upload/jquery.uploadify.js" type="text/javascript"></script>
<script src="../../../Scripts/upload/jquery.uploadify.min.js" type="text/javascript"></script>
<script src="../../../Scripts/upload/swfobject.js" type="text/javascript"></script>
<link href="../../../Scripts/upload/uploadify.css" rel="stylesheet" type="text/css" />
//JS方法
<script type="text/javascript">
$(document).ready(function () {
$("#uploadify").uploadify({
‘uploader‘: ‘/Scripts/upload/uploadify.swf‘,
‘script‘: ‘Uploads.ashx‘,
‘scriptData‘: { ‘lyh‘: ‘<%=Request.QueryString["lyh"] %>‘, ‘lc‘: ‘<%=Request.QueryString["lc"] %>‘, ‘HandlerType‘: ‘file‘ },
‘method‘: ‘Get‘,
‘cancelImg‘: ‘/Scripts/upload/cancel.png‘,
‘buttonImg‘: ‘/Scripts/upload/uploadbtn.png‘,
‘buttonText‘: ‘‘,
‘width‘: 120,
‘height‘: 28,
‘queueID‘: ‘fileQueue‘,
‘auto‘: false,
‘multi‘: true,
‘queueSizeLimit‘: 10,
‘simUploadLimit‘: 1,
‘onInit‘: function () {
},
‘onSelect‘: function (e, queueId, fileObj) {
},
‘onComplete‘: function (event, queueId, fileObj, response, data) {
if (response == "null") {
$.messager.alert("系统提示", "未选择需要上传的文件。", "error");
} else if (response == "error") {
$.messager.alert("系统提示", "上传文件时发生错误。", "附件格式不对");
} else {
$.messager.alert("系统提示", "上传成功");
}
}
});
});
//获取附件信息
function getAttachment() {
$.ajax({
type: "GET",
dataType: "text",
async: false,
url: ‘<%=ResolveUrl("/Ajax/Common/Attachment.ashx")%>‘,
data: "HandlerType=getequipment&lyh=" + ‘<%=Request.QueryString["lyh"] %>‘ + "&lc=" + ‘<%=Request.QueryString["lc"] %>‘ + "&rand=" + newCommon.atrand(10000000),
success: function (msg) {
var table = "";
if (msg != "") {
table = "<table class=‘list‘ style=‘width:460px; margin-top:10px;margin-bottom:10px; margin-left:10px‘>";
table += "<thead>";
table += "<tr style=‘height:28px;‘>";
table += "<th align=‘left‘ style=‘border-left:1px solid #5f89c6‘> 楼宇号</th>";
table += "<th align=‘center‘ style=‘width:15%‘>楼层</th>";
table += "<th align=‘center‘ style=‘width:15%;‘>上传上传人</th>";
table += "<th style=‘width:20%;‘ align=‘center‘>操作</th>";
table += "</tr>";
table += "</thead>";
table += "<tbody>";
var info = msg.split(‘|‘);
for (var i = 0; i < info.length; i++) {
var name = info[i].split(‘,‘);
table += "<tr style=‘height:28px;‘><td align=‘left‘ style=‘border-left:1px solid #5f89c6‘> " + name[1] + "</td>";
table += "<td align=‘center‘> " + name[2] + "</td>";
table += "<td align=‘center‘> " + name[3] + "</td>";
table += "<td align=‘center‘><a class=‘abtn2‘ style=‘cursor:pointer; width:40px‘ href=‘/Ajax/Common/Attachment.ashx?HandlerType=download&id=" + name[0] + "‘ target=‘frm‘>下载</a>";
table += " <a class=‘abtn2‘ style=‘cursor:pointer; width:40px‘ onclick=‘deldata(\"" + name[0] + "\")‘>删除</a>";
table += "</td></tr>";
}
table += "</tbody>";
table += "</table>";
}
$("#divattachment").html(table);
}
});
}
//删除
function deldata(attid) {
$.messager.confirm(‘系统提示‘, ‘确定要删除该附件‘, function (r) {
if (r) {
$.ajax({
type: "GET",
dataType: "json",
async: false,
url: ‘<%=ResolveUrl("../../../Ajax/Common/Attachment.ashx")%>‘,
data: "HandlerType=delattinfo&id=" + attid + "&rand=" + newCommon.atrand(10000000),
success: function (data) {
if (data.State == "1")
getAttachment();
else
$.messager.alert("系统提示", data.Message, "error");
}
});
}
});
}
</script>
//HTML代码
//显示进度条
<div style="padding: 1px;">
<div id="fileQueue">
</div>
</div>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="border: 0px;">
<input type="file" name="uploadify" id="uploadify" />
</td>
<td style="border: 0px;">
<a id="btnUpload" plain="true" class="easyui-linkbutton" iconcls="icon-ok" onclick=" javascript:$(‘#uploadify‘).uploadifyUpload(); ">
上传文件</a>
</td>
<td style="border: 0px;">
<a id="btnCancle" plain="true" class="easyui-linkbutton" iconcls="icon-cancel" onclick=" javascript:$(‘#uploadify‘).uploadifyClearQueue(); ">
取消上传</a>
</td>
</tr>
</table>
//显示附件列表
<div id="divattachment">
</div>
//一般处理程序代码
public override void OnRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string HandleType = context.Request["HandlerType"].ToLower();
switch (HandleType)
{
case "file": //获取自定义树形结构
GetFIle(context);
break;
}
}
#region 获取设备树
/// <summary>
/// 附件处理
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private void GetFIle(HttpContext context)
{
Mes oMes = new Mes();
context.Response.ContentType = "text/plain";
try
{
string basePath = Hzjg.Common.Config.ConfigManage.fGetAppConfig("SaveFilePath");
HttpPostedFile file = context.Request.Files["FileData"];
string extension = Path.GetExtension(file.FileName).ToUpper();
if (extension != ".PDF" && extension != ".PNG" && extension != ".GIF" && extension != ".JPEG" && extension != ".JPG")
{
context.Response.Write("格式不对");
}
else
{
if (file != null)
{
#region 执行文件上传
string documentPath = @"\files\" + context.Request["lyh"] + @"\消防设备图纸\";
if (!Directory.Exists(basePath + documentPath))
Directory.CreateDirectory(basePath + documentPath);
if (!File.Exists(basePath + documentPath))
{
file.SaveAs(basePath + documentPath + file.FileName);
Model.LOGISTICS_BUILDINGEQUIPMENTPIC model = new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
model = cBll.GetList(" where t.LYH=‘" + context.Request["lyh"] + "‘ and t.LC=‘" + context.Request["lc"] + "‘", "").FirstOrDefault();
if (model != null)
{
model.PICTUREPATH = documentPath.Replace("\\", "/") + file.FileName;
oMes = new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Update(model);
}
else
{
model = new Model.LOGISTICS_BUILDINGEQUIPMENTPIC();
model.ID = Guid.NewGuid().ToString();
model.LYH = context.Request["lyh"];
model.LC = decimal.Parse(context.Request["lc"]);
model.PICTUREPATH = documentPath.Replace("\\", "/") + file.FileName;
model.INPUTTIME = DateTime.Now;
model.INPUTCODE = JG.Base.Portal.AppCode.Data.CurrentUserInfo.UserCode;
oMes = new BLL.LOGISTICS_BUILDINGEQUIPMENTPIC().Add(model);
}
}
#endregion
}
}
}
catch (Exception ex)
{
Hzjg.Common.Utility.Log.fWriterLog("上传发文附件异常:" + ex.Message, ex);
}
context.Response.Write("Succeed");
}
#endregion
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。