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
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4