欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

图片,视频,其他资源上传

程序员文章站 2022-07-10 23:48:48
/// /// 图片,视频,其他资源上传 /// /// 文件名称 /// 上传类型 /// 保存 ......

/// <summary>
/// 图片,视频,其他资源上传
/// </summary>
/// <param name="filename,">文件名称</param>
/// <param name="typestyle">上传类型</param>
/// <param name="j">保存文件名随机数标识</param>
public static string fileupdate(httpfilecollection files, string filename, int typestyle,int j)
{
if (filename == null)
{
return string.empty;
}
string fileext = path.getextension(filename);
//读取存储路劲地址
string uploadpath = configval("uploadpath");
string path = null;
if (typestyle == 1)//图片上传
{
if (!(fileext == ".jpg" || fileext == ".jpeg" || fileext == ".bmp" || fileext == ".gif" || fileext == ".png"))
{
return string.empty;
}
path = string.format("{0}/{1}{2}", uploadfolder(uploadtype.preimg), datetime.now.tostring("yyyymmddhhmmssfff"), fileext);
}
else if (typestyle == 2)//视频
{
if (!(fileext == ".mp4" || fileext == ".3gp" || fileext == ".wmv" || fileext == ".mpg" || fileext == ".avi"))
{
//不是视频
return string.empty;
}
path = string.format("{0}/{1}{2}", uploadfolder(uploadtype.video), datetime.now.tostring("yyyymmddhhmmssfff"), fileext);
}
else
{
path = string.format("{0}/{1}{2}", uploadfolder(uploadtype.resource), datetime.now.tostring("yyyymmddhhmmssfff"), fileext);
}

//3.获得网站的绝对路径 存储文件
string filename = string.format("{0}/{1}", uploadpath, path);
files[j].saveas(filename);
return path;
}