AJAX上传图片,使用ajaxupload

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

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

 

SCRIPT

 




 

 HTML





 AjaxUpload.ashx

<%@ WebHandler Language="C#" Class="AjaxUpload" %>

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();

    }
}

你可能感兴趣的:(Js,Asp.Net,JQuery)