///// <summary> ///// 上传视频 ///// </summary> //public static string UploadVideo(UploadedFile oFile) //{ // try // { // // Get the uploaded file name. // string sFileName = System.IO.Path.GetFileName(oFile.ClientName);//原文件名 // if (sFileName != "") // { // string FileTxt = System.IO.Path.GetExtension(oFile.ClientName);//扩展名 // string nFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();//当前时间 // Random sran = new Random();//取随机数; // string Rand = sran.Next(1, 9).ToString(); // sFileName = nFileName + Rand + FileTxt;//新的文件名(当前时间+1位随机数) // string reFileName = sFileName;//返回 // //取保存目录 // string sFilePath = ConfigurationManager.AppSettings["VideoUpload"]; // //上传时间月份的文件夹(如:2007-1) // //edit by yjihrp // //string reFileP = "http://flv.ipow.cn" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; // string reFileP = "http://sys.ipow.cn/upload" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; // sFilePath = "~/Upload" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; // //建立目录 // FileDirectoryHelper.CreateFolder(sFilePath); // string reFilePath = sFilePath;//返回 // //路径 // sFilePath = System.Web.HttpContext.Current.Server.MapPath(sFilePath); // string strFilePath = System.IO.Path.Combine(sFilePath, sFileName); // oFile.SaveAs(strFilePath); // string returntemp = reFileP + "|" + reFileName; // return returntemp; // } // else // { // return null; // } // } // catch // { // return null; // } //} /// <summary> /// 上传视频 edit by yjihrp 2011.4.12 /// </summary> public static string ClientUploadVideo(HttpPostedFile f) { try { // Get the uploaded file name. string sFileName = System.IO.Path.GetFileName(f.FileName);//原文件名 if (sFileName != "") { string FileTxt = System.IO.Path.GetExtension(f.FileName); //扩展名 string nFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); //当前时间 Random sran = new Random(); //取随机数; string Rand = sran.Next(1, 9).ToString(); sFileName = nFileName + Rand + FileTxt; //新的文件名(当前时间+1位随机数) string reFileName = sFileName; //返回 //取保存目录 string sFilePath = ConfigurationManager.AppSettings["VideoUpload"]; //上传时间月份的文件夹(如:2007-1) //edit by yjihrp 2011.4.11 //string reFileP = "http://flv.ipow.cn" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; string reFileP = "http://flv.ipow.cn" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; sFilePath = "~/Upload" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/Source/"; //建立目录 FileDirectoryHelper.CreateFolder(sFilePath); string reFilePath = sFilePath;//返回 //路径 // sFilePath = System.Web.HttpContext.Current.Server.MapPath(sFilePath); string copySFilePath = System.Web.HttpContext.Current.Server.MapPath(sFilePath); string strFilePath = System.IO.Path.Combine(copySFilePath, sFileName); f.SaveAs(strFilePath); // edit by yjihrp 2011.4.14 string ffPath = System.Web.HttpContext.Current.Server.MapPath("~/Upload/flv/ffmpeg.exe"); FfmpegHelper ffmpeg = new FfmpegHelper(ffPath); ffmpeg.ToJpg(strFilePath); string catchImgFileName = System.IO.Path.ChangeExtension(reFileName, ".jpg"); string returntemp = reFileP + "|" + reFileName + "|" + catchImgFileName; //string returntemp = reFileP + "|" + reFileName ; return(returntemp); } else { return(null); } } catch { return(null); } }
/// <summary> /// 图片下载 /// </summary> /// <param name="strUrl"></param> /// <param name="strPath"></param> /// <param name="strTxt"></param> /// <returns></returns> public static string[] DownPhoto(string strUrl, string strPath, string strTxt) { try { if (strUrl != "") { string[] aPicInfo = new string[2]; strPath = "~/upload" + ConfigurationManager.AppSettings["RemotePath"] + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; string strReFile = "http://img.ipow.cn" + ConfigurationManager.AppSettings["RemotePath"] + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; string sFileName = "", strDownPath = ""; string nFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); //当前时间 Random sran = new Random(); //取随机数; string Rand = sran.Next(1, 9).ToString(); sFileName = nFileName + Rand + strTxt; //新的文件名(当前时间+1位随机数) string reFileName = sFileName; //返回图片上传后名称 strDownPath = strPath; FileDirectoryHelper.CreateFolder(strPath); FileDirectoryHelper.SavePhotoFromUrl(strPath + sFileName, strUrl); if (strTxt.ToLowerInvariant() == ".jpg" || strTxt.ToLowerInvariant() == ".gif" || strTxt.ToLowerInvariant() == ".bmp" || strTxt.ToLowerInvariant() == ".png") { string CutPath = strPath + "CutDown\\"; FileDirectoryHelper.CreateFolder(CutPath); CutPath = System.Web.HttpContext.Current.Server.MapPath(CutPath); string sFilePath = System.Web.HttpContext.Current.Server.MapPath(strPath); string strFilePath = System.IO.Path.Combine(sFilePath, sFileName); //生成缩略图135X125 string tFilePath = CutPath + "135_125_" + sFileName; MakeImage(strFilePath, tFilePath, 135, 125, "cut"); //生成缩略图125X111 tFilePath = CutPath + "125_111_" + sFileName; MakeImage(strFilePath, tFilePath, 125, 111, "cut"); //生成缩略图64X50 tFilePath = CutPath + "64_50_" + sFileName; MakeImage(strFilePath, tFilePath, 64, 50, "cut"); //生成缩略图640 tFilePath = sFilePath + "ipow" + sFileName; MakeImage(strFilePath, tFilePath, 640, 0, "w"); } string strw = System.Web.HttpContext.Current.Server.MapPath("/UpLoad/") + "water.gif"; if (ConfigurationManager.AppSettings["WaterMark"].ToString() == "1") { string sFilePath = System.Web.HttpContext.Current.Server.MapPath(strPath); string strFilePath = System.IO.Path.Combine(sFilePath, "ipow" + sFileName); string wFilePath = System.IO.Path.Combine(sFilePath, "i" + sFileName);//水印图 ToMarkWater(strFilePath, strw, strw, wFilePath, 2); //if (System.IO.File.Exists(strFilePath)) //{ // System.IO.File.Delete(strFilePath); //} } aPicInfo[0] = strReFile; aPicInfo[1] = "i" + sFileName; return(aPicInfo); } else { return(null); } } catch { return(null); } }
//#region 图片上传 ///// <summary> ///// 图片上传 ///// </summary> ///// <param name="oFile"></param> ///// <param name="IsWater">是否需要水印,0为不需要;1为需要</param> ///// <param name="IsSmall">是否需要缩略图,0为不需要;1为需要</param> ///// <param name="iType">图片类别,0为精彩图片;1为LOGO;2为编辑器上传的图片;3为导游图;4为设备图片;5为访谈人物图片;6为酒店图片</param> ///// <returns>上传后的路径</returns> //public static string UploadPic(UploadedFile oFile, int IsWater, int IsSmall, int iType) //{ // try // { // string sFileName = System.IO.Path.GetFileName(oFile.ClientName); // if (sFileName != "") // { // string FileTxt = System.IO.Path.GetExtension(oFile.ClientName);//扩展名 // string nFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();//当前时间 // Random sran = new Random();//取随机数; // string Rand = sran.Next(1, 9).ToString(); // sFileName = nFileName + Rand + FileTxt;//新的文件名(当前时间+1位随机数) // string reFileName = sFileName;//返回图片上传后名称 // string sFilePath = "", tFilePath = "", reFilePath1 = ""; ; // switch (iType) // { // case 0: // sFilePath = ConfigurationManager.AppSettings["PicPath"]; // break; // case 1: // sFilePath = ConfigurationManager.AppSettings["LogoPath"]; // break; // case 2: // sFilePath = ConfigurationManager.AppSettings["EditPath"]; // break; // case 3: // sFilePath = ConfigurationManager.AppSettings["MapPicPath"]; // break; // case 5: // sFilePath = ConfigurationManager.AppSettings["ActivityPath"]; // break; // default: // break; // } // //上传时间月份的文件夹(如:2007-1) // reFilePath1 = "http://img.ipow.cn" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; // sFilePath = "/Upload" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; // //建立目录 // FileDirectoryHelper.CreateFolder(sFilePath); // string reFilePath = sFilePath;//返回图片上传后路径 // string CutPath = sFilePath + "CutDown/"; // FileDirectoryHelper.CreateFolder(CutPath); // //路径 // sFilePath = System.Web.HttpContext.Current.Server.MapPath(sFilePath); // CutPath = System.Web.HttpContext.Current.Server.MapPath(CutPath); // string strFilePath = System.IO.Path.Combine(sFilePath, sFileName); // oFile.SaveAs(strFilePath); // if (IsSmall == 1) // { // if (FileTxt.ToLowerInvariant() == ".jpg" || FileTxt.ToLowerInvariant() == ".gif" || FileTxt.ToLowerInvariant() == ".bmp" || FileTxt.ToLowerInvariant() == ".png") // { // if (iType == 5) // { // //生成缩略图118X118 // tFilePath = CutPath + "261_161_" + sFileName; // MakeImage(strFilePath, tFilePath, 261, 161, "cut"); // } // else // { // //生成缩略图150X150 // tFilePath = CutPath + "160_150_" + sFileName; // MakeImage(strFilePath, tFilePath, 160, 150, "cut"); // //ToThumbNail(strFilePath, 160, 150, FileTxt, tFilePath); // //生成缩略图126X99 // tFilePath = CutPath + "126_99_" + sFileName; // MakeImage(strFilePath, tFilePath, 126, 99, "cut"); // //ToThumbNail(strFilePath, 126, 99, FileTxt, tFilePath); // //生成缩略图116X103 // tFilePath = CutPath + "116_103_" + sFileName; // MakeImage(strFilePath, tFilePath, 116, 103, "cut"); // //ToThumbNail(strFilePath, 116, 103, FileTxt, tFilePath); // //生成缩略图240X210 // tFilePath = CutPath + "240_210_" + sFileName; // MakeImage(strFilePath, tFilePath, 240, 210, "cut"); // } // //生成缩略图550 // tFilePath = sFilePath + "ipow_" + sFileName; // MakeImage(strFilePath, tFilePath, 640, 0, "w"); // } // } // if (IsWater == 1) // { // string strw = System.Web.HttpContext.Current.Server.MapPath("~/UpLoad/") + "water.gif"; // if (ConfigurationManager.AppSettings["WaterMark"].ToString() == "1") // { // string wFilePath = sFilePath + "ipow" + sFileName;//水印图 // ToMarkWater(tFilePath, strw, strw, wFilePath, 2); // //if (System.IO.File.Exists(strFilePath)) // //{ // // System.IO.File.Delete(strFilePath); // //} // } // } // return reFilePath1 + "|" + reFileName; // } // else // { // return null; // } // } // catch // { // return null; // } //} //#endregion #region 客户端图片上传 /// <summary> /// 图片上传 /// </summary> /// <param name="oFile"></param> /// <param name="IsWater">是否需要水印,0为不需要;1为需要</param> /// <param name="IsSmall">是否需要缩略图,0为不需要;1为需要</param> /// <param name="iType">图片类别,0为精彩图片;1为LOGO;2为编辑器上传的图片;3为导游图;4为设备图片;5为访谈人物图片;6为酒店图片</param> /// <returns>上传后的路径</returns> public static string ClientUploadPic(HttpPostedFile oFile, int IsWater, int IsSmall, int iType) { try { string sFileName = System.IO.Path.GetFileName(oFile.FileName); if (sFileName != "") { string FileTxt = System.IO.Path.GetExtension(oFile.FileName); //扩展名 string nFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); //当前时间 Random sran = new Random(); //取随机数; string Rand = sran.Next(1, 9).ToString(); sFileName = nFileName + Rand + FileTxt; //新的文件名(当前时间+1位随机数) string reFileName = sFileName; //返回图片上传后名称 string sFilePath = "", tFilePath = "", reFilePath1 = "";; switch (iType) { case 0: sFilePath = ConfigurationManager.AppSettings["PicPath"]; break; case 1: sFilePath = ConfigurationManager.AppSettings["LogoPath"]; break; case 2: sFilePath = ConfigurationManager.AppSettings["EditPath"]; break; case 3: sFilePath = ConfigurationManager.AppSettings["MapPicPath"]; break; case 5: sFilePath = ConfigurationManager.AppSettings["ActivityPath"]; break; case 6: //edit by yjihrp 2011.4.18.9.37 sFilePath = ConfigurationManager.AppSettings["HotelPicPath"]; break; default: break; } //上传时间月份的文件夹(如:2007-1) reFilePath1 = "http://img1.ipow.cn" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; sFilePath = "~/Upload" + sFilePath + "/" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "/"; //建立目录 FileDirectoryHelper.CreateFolder(sFilePath); string reFilePath = sFilePath;//返回图片上传后路径 string CutPath = sFilePath + "CutDown/"; FileDirectoryHelper.CreateFolder(CutPath); //路径 sFilePath = System.Web.HttpContext.Current.Server.MapPath(sFilePath); CutPath = System.Web.HttpContext.Current.Server.MapPath(CutPath); string strFilePath = System.IO.Path.Combine(sFilePath, sFileName); oFile.SaveAs(strFilePath); if (IsSmall == 1) { if (FileTxt.ToLowerInvariant() == ".jpg" || FileTxt.ToLowerInvariant() == ".gif" || FileTxt.ToLowerInvariant() == ".bmp" || FileTxt.ToLowerInvariant() == ".png") { if (iType == 5) { //生成缩略图118X118 tFilePath = CutPath + "261_161_" + sFileName; MakeImage(strFilePath, tFilePath, 261, 161, "cut"); } else { //生成缩略图150X150 tFilePath = CutPath + "160_150_" + sFileName; MakeImage(strFilePath, tFilePath, 160, 150, "cut"); //ToThumbNail(strFilePath, 160, 150, FileTxt, tFilePath); //生成缩略图126X99 tFilePath = CutPath + "126_99_" + sFileName; MakeImage(strFilePath, tFilePath, 126, 99, "cut"); //ToThumbNail(strFilePath, 126, 99, FileTxt, tFilePath); //生成缩略图116X103 tFilePath = CutPath + "116_103_" + sFileName; MakeImage(strFilePath, tFilePath, 116, 103, "cut"); //ToThumbNail(strFilePath, 116, 103, FileTxt, tFilePath); //生成缩略图240X210 tFilePath = CutPath + "240_210_" + sFileName; MakeImage(strFilePath, tFilePath, 240, 210, "cut"); } //生成缩略图550 tFilePath = sFilePath + "ipow_" + sFileName; MakeImage(strFilePath, tFilePath, 640, 0, "w"); } } if (IsWater == 1) { //在这里,得有一个water.gif水印图片哈 string strw = System.Web.HttpContext.Current.Server.MapPath("~/UpLoad/") + "water.gif"; if (ConfigurationManager.AppSettings["WaterMark"].ToString() == "1") { string wFilePath = sFilePath + "ipow" + sFileName;//水印图 ToMarkWater(tFilePath, strw, strw, wFilePath, 2); //if (System.IO.File.Exists(strFilePath)) //{ // System.IO.File.Delete(strFilePath); //} } } return(reFilePath1 + "|" + reFileName); } else { return(null); } } catch { return(null); } }