关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

hbuider后台接收图片例子

发布时间:2019-11-12 16:41:23

hbulider后台接受图片的例子,代码分享:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
 
namespace DTcms.Web.test
{
    /// <summary>
    /// appupload 的摘要说明
    /// </summary>
    public class appupload : IHttpHandler
    {
 
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string dirPath = context.Server.MapPath("~/Temp/");
            if (!Directory.Exists(dirPath))//如果目录不存在创建目录
            {
                Directory.CreateDirectory(dirPath);
            }
            try
            {
                HttpFileCollection files = context.Request.Files;
                if (files.Count > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFile file = context.Request.Files[i];
                        string filePath = dirPath + file.FileName + ".jpg";//为了上传重复,这里可以任意修改
                        file.SaveAs(filePath);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
 
        }
 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

假如上传视频怎么办?

以上接收程序要改写。另外。在前台js做过滤

plus.gallery.pick( function(path){
        console.log(path);
    }, function ( e ) {
        console.log( "取消选择图片" );
    }, {filter:"image"} );//上传文件类型过滤  //如果是上传视频是video



/template/Home/Zkeys/PC/Static