首页 > 代码库 > uploadfile图片上传和ashx
uploadfile图片上传和ashx
uploadify.swf需要是支持中文 | |
$(function () { | |
//获取所有上传按钮id | |
$("div[id^=‘fileInput_‘]").each(function () { | |
var name = $(this).attr("id"); | |
create(name); | |
}); | |
}); | |
function create(name) { | |
var select = "上传图片"; | |
if (name.indexOf("_") > -1) { | |
if (name.substring(name.lastIndexOf("_") + 1) == "1") { | |
var select = "大图"; | |
} | |
else if (name.substring(name.lastIndexOf("_") + 1) == "2") { | |
select = "小图"; | |
} | |
} | |
$(‘#‘ + name).uploadify({ | |
‘uploader‘: ‘/uploadify/uploadify.swf‘, | |
‘script‘: ‘Pro_Sub.aspx?upfile=1‘, | |
‘cancelImg‘: ‘/uploadify/cancel.png‘, | |
‘folder‘: ‘/ProductImg/‘, | |
‘fileExt‘: ‘*.jpg;*.gif;*.png;*.bmp;*.JPEG;‘, | |
‘fileDesc‘: ‘请选择 *.jpg;*.gif;*.png,*.bmp;*.JPEG 格式的图片‘, | |
‘multi‘: true, | |
‘auto‘: true, | |
‘buttonText‘:select, | |
‘onComplete‘: function (event, queueId, fileObj, response, data) { | |
var re = response.split(‘|@|‘); | |
if (re[0] == "1") { | |
var box = name.substring(10); | |
var html = "<div class=‘ImgHtml‘ OnClick=‘change(this)‘><input class=‘input2‘ style=‘display: none;‘ type=‘button‘ value=http://www.mamicode.com/‘删   除‘ onclick=‘delImg(this);showfi("+name.replace("_",".")+");‘ /><input type=‘checkbox‘ checked=‘checked‘ class=‘hide‘ value=http://www.mamicode.com/‘" + re[1] + "‘ /><img class=‘Img‘ src=http://www.mamicode.com/‘" + re[1] + "‘></div>"; | |
if (box == "1_0") { | |
$("#ContentPlaceHolder1_rpAttribute_txtvalue_4").val(re[1]); | |
html = "<div class=‘ImgHtml‘ OnClick=‘change(this)‘><input class=‘input2‘ style=‘display: none;‘ type=‘button‘ value=‘删   除‘ onclick=‘delImg(this);showfi(1)‘ /><input type=‘checkbox‘ class=‘hide‘ value=http://www.mamicode.com/‘" + re[1] + "‘ /><img class=‘Img‘ src=http://www.mamicode.com/‘" + re[1] + "‘></div>"; | |
$("#file0").hide(); | |
} | |
$(".box" + box).append(html); | |
} else { | |
ymPrompt.errorInfo({ message: "上传失败!", showMask: true }); | |
} | |
} | |
}); | |
} | |
</script>
============================================================================= using System; using System.Web.SessionState; namespace Admin.TkAdmin.Product string upfile = Request["upfile"]; //对上传的图片进行保存到指定文件中 int rInt = ra.Next(1000); Session["IntIndexImg"] = rInt; newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + rInt + Path.GetExtension(file.FileName).ToUpper(); }catch //用于创建目录 } public bool IsReusable |
uploadfile图片上传和ashx