?? upload.aspx.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 + -