62,046
社区成员
发帖
与我相关
我的任务
分享
<form action="ReAdd3.aspx" id="form2" method="post" enctype="multipart/form-data" target="upload" >
</form>
<iframe name="upload" style="display:none"></iframe>
function upLoadFile()
{
var options = {
type: "POST",
url: 'Files.ashx',
success: showResponse
};
// 将options传给ajaxForm
$('#myForm').ajaxSubmit(options);//myForm为你页面的form的id
}
//上传成功后事件
function showResponse()
{
alert("上传成功!");
}
public void ProcessRequest(HttpContext context)
{
HttpFileCollection files = context.Request.Files;
if (files.Count > 0)
{
Random rnd = new Random();
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (file.ContentLength > 0)
{
string fileName = file.FileName;
string extension = Path.GetExtension(fileName);
int num = rnd.Next(5000, 10000);
string path = "file/" + num.ToString() + extension;
file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
}
}
}
}