用ajax来上传图片,AJAX上传图片,使用ajaxupload

首先从网上下载一个ajaxupload.3.6.js

也可以我的资源下载 ajaxupload.3.6.js

SCRIPT

HTML

1297897474530287616.htm

AjaxUpload.ashx

using System;

using System.Web;

using System.Text;

using BLL;

using System.IO;

using Common;

public class AjaxUpload : IHttpHandler

{

#region 属性

private B_YP_Members _Member = new B_YP_Members();

#endregion

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

if (context.Request.ServerVariables["HTTP_REFERER"] == null)

{

context.Response.Write("不要这样访问");

context.Response.End();

}

string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();

string fullFileName = GetFileName() + strExtension;

string strSaveLocation = context.Server.MapPath("~/UploadFile/Img/") + fullFileName;

context.Request.Files[0].SaveAs(strSaveLocation);

context.Response.Write(fullFileName);

context.Response.Flush();

context.Response.End();

}

public bool IsReusable

{

get

{

return false;

}

}

private string GetFileName()

{

Random rd = new Random();

StringBuilder serial = new StringBuilder();

serial.Append(DateTime.Now.ToString("yyyyMMddHHmmss"));

serial.Append(rd.Next(100000, 999999).ToString());

return serial.ToString();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值