⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload.aspx.cs

📁 一阵子
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace PSP
{
	/// <summary>
	/// Summary description for upload.
	/// </summary>
	public class upload : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtTitle;
		protected System.Web.UI.WebControls.TextBox txtDesc;
		protected System.Web.UI.HtmlControls.HtmlInputFile uplTheFile;
		protected System.Web.UI.WebControls.Button btAdd;
		protected System.Web.UI.WebControls.Label lblMsg;
		protected System.Web.UI.WebControls.Literal litItems;
	
		string _userID;

		private void Page_Load(object sender, System.EventArgs e)
		{
			this._userID = PSP.User.CheckUser(Page);
			if(!Page.IsPostBack)
			{
				DataTable dt = Framework.GetUserItems(this._userID);
				this.litItems.Text = CMS.GenerateItemList2(dt);

				this.btAdd.Attributes.Add("onclick","document.getElementById('lblMsg').innerHTML='上传中,请耐心等待...';" );
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btAdd.Click += new System.EventHandler(this.btAdd_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btAdd_Click(object sender, System.EventArgs e)
		{
			if(this.txtTitle.Text.Trim().Length ==0)
			{
				this.lblMsg.Text = "标题不能为空";
				return;
			}

			string strBaseLocation = System.Configuration.ConfigurationSettings.AppSettings["TargetFolder"] ;
			string filename = "";

			if (null != uplTheFile.PostedFile && uplTheFile.PostedFile.ContentLength > 0 ) 
			{
				if(uplTheFile.PostedFile.ContentLength> 4 * 1024 * 1024)
				{
					lblMsg.Text = "文件大小超过4M!";
					return;
				}
				System.IO.FileInfo fi = new System.IO.FileInfo(uplTheFile.PostedFile.FileName);
				if(fi.Extension.ToLower() != ".avi" && fi.Extension.ToLower() != ".wmv" && fi.Extension.ToLower() != ".flv")
				{
					lblMsg.Text = "文件格式应为AVI, WMV, FLV视频! 现在格式为:" + fi.Extension.ToLower();
					return;
				}

				filename = Guid.NewGuid().ToString() + fi.Name;

				try 
				{						
					uplTheFile.PostedFile.SaveAs(strBaseLocation + @"old\" + filename);
				}
				catch (Exception ee) 
				{
					throw ee;
				}
			}

			string itemID = Framework.AddNewItem(this._userID,CMS.HandleString(this.txtTitle.Text),
				CMS.HandleString(this.txtDesc.Text), CMS.HandleString(this.txtDesc.Text));	

			string fileName = System.Configuration.ConfigurationSettings.AppSettings["FFMpeg"];

			string orginalFile = strBaseLocation + @"old\" + filename;
			string targetFile = strBaseLocation + itemID + ".flv";
			string argu = @"-i " + orginalFile + " -ab 56 -ar 22050 -b 500 -r 15 -s 480x360 " + targetFile;

			try
			{
				if(! fileName.EndsWith(".flv"))
				{
					try
					{
						System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(fileName,argu);
						System.Diagnostics.Process.Start(startInfo);
					}
					catch
					{
						throw;
					}

					System.Threading.Thread.Sleep(6000);
				}
				else
				{
					System.IO.File.Copy(orginalFile, targetFile);
				}
				
				//picture
				argu = @"-i " + targetFile + " -y -f image2 -ss 08.010 -t 0.001 -s 352x240 " + strBaseLocation + itemID + ".jpg";
				System.Diagnostics.ProcessStartInfo startInfo1 = new System.Diagnostics.ProcessStartInfo(fileName,argu);				
				System.Diagnostics.Process.Start(startInfo1);
				System.Threading.Thread.Sleep(2000);

				if(! System.IO.File.Exists(strBaseLocation + itemID + ".jpg"))
				{
					System.IO.File.Copy(strBaseLocation + "17.jpg", strBaseLocation + itemID + ".jpg");
				}

			}
			catch(Exception ee)
			{
				throw ee;
			}
			
			if(System.IO.File.Exists(targetFile) && (new System.IO.FileInfo(targetFile)).Length>10000)
			{								
				this.lblMsg.Text = "<a href='viewitem.aspx?itemid=" + itemID + "'>添加成功!</a>";
			}
			else
			{
				System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(fileName,argu);
				System.Diagnostics.Process.Start(startInfo);

				if(System.IO.File.Exists(targetFile) && (new System.IO.FileInfo(targetFile)).Length>10000)
				{
					this.lblMsg.Text = "<a href='viewitem.aspx?itemid=" + itemID + "'>添加成功!</a>";
				}
				else
				{				
					Framework.DeleteItem(itemID, this._userID);									
					this.lblMsg.Text = "此文件格式添加失败!";
				}
			}

		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -