/// <summary> /// 圖片,視頻,其他資源上傳 /// </summary> /// <param name="FileName,">文件名稱</param> /// <param name="typestyle">上傳類型</param> /// <param name="j">保存 ...
/// <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;
}