图片,视频,其他资源上传
/// <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;
}
上一篇: php下删除字符串中HTML标签的函数
下一篇: 继续收藏一些PHP常用函数第1/2页
推荐阅读