layui 批量上传
阅读原文时间:2023年07月11日阅读:2
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="piclist.aspx.cs" Inherits="XGHUNLIAN.admin.member.piclist" %>

<%@ Import Namespace="XGHUNLIAN.Common" %>


会员照片列表


会员照片列表


头像:
UID:
OPENID:
微信昵称:
真实名称:
电话号码:



  • <%# htmlstr(Eval("imgurl").ToString())%>



文件名 大小 状态 操作









using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace XGHUNLIAN.tools
{
///

/// UploadFile 的摘要说明 ///
public class UploadFile : IHttpHandler
{

    public void ProcessRequest(HttpContext context)  
    {  
        //context.Response.ContentType = "text/plain";  
        //context.Response.Write("Hello World");  
        string shipin = "\*.avi \*.rmvb \*.rm \*.asf \*.divx \*.mpg \*.mpeg \*.mpe \*.wmv \*.mp4 \*.mkv \*.vob";  
        string allowExtension =string.Join("|",new string \[\]{ ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".JPG", ".JPEG", ".GIF", ".BMP", ".PNG" });  
        if (context.Request.Files.Count > )  
        {  
            for (int i = ; i < context.Request.Files.Count; i++)  
            {  
                HttpPostedFile filePost = context.Request.Files\[i\]; // 获取上传的文件  
                string aFile = filePost.FileName;  
                string aLastName = aFile.Substring(aFile.LastIndexOf(".") + , (aFile.Length - aFile.LastIndexOf(".") - )); //扩展名

                if (shipin.IndexOf(aLastName) == - && allowExtension.IndexOf(aLastName) == -)  
                {  
                    context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}");  
                    context.Response.End();  
                }  
                string filename = "";  
                string filePath = SaveExcelFile(filePost,ref filename); // 保存文件并获取文件路径  
                BLL.wei\_Member bll = new BLL.wei\_Member();

                if (bll.AddImgUrl(context.Request.QueryString\["openid"\], filename))  
                {  
                    context.Response.Write("{\\"code\\":\\"0\\",\\"data\\":\\"" + filename + "\\"}");  
                    context.Response.End();  
                }  
                context.Response.Write("{\\"code\\":\\"1\\",\\"data\\":\\"\\"}");  
                context.Response.End();  
            }  
        }  
    }

    public bool IsReusable  
    {  
        get  
        {  
            return false;  
        }  
    }  
    public  string SaveExcelFile(HttpPostedFile file,ref string filename\_)  
    {  
        try  
        {  
            var fileName = file.FileName.Insert(file.FileName.LastIndexOf('.'), "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff"));  
            var filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/Image"), fileName);  
            string directoryName = Path.GetDirectoryName(filePath);  
            if (!Directory.Exists(directoryName))  
            {  
                Directory.CreateDirectory(directoryName);  
            }  
            file.SaveAs(filePath);  
            filename\_ = fileName;  
            return filePath;  
        }  
        catch  
        {  
            return string.Empty;  
        }  
    }  
}  复制

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章