即时尝试在asp.net上传视频,但正在帮我一些朋友 [英] im try to video upload in asp.net but is working help me some me friends

查看:67
本文介绍了即时尝试在asp.net上传视频,但正在帮我一些朋友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Htm design



Htm design

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <table style="width:100%;">
        <tr>
            <td>
                Video title</td>
            <td>
                <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                Video Content</td>
            <td>
                <asp:TextBox ID="txtContent" runat="server" Height="104px" TextMode="MultiLine"

                    Width="207px"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                upload video</td>
            <td>
                <asp:FileUpload ID="fileupVideo" runat="server" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                video type</td>
            <td>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Button ID="btnUpVideo" runat="server" OnClick="btnUpVideo_Click"

                    Text="Upload" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>
</html>









App_Code



使用系统;

使用System.Data;

使用System.Configuration;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System .Web.UI.WebControls.WebParts;

使用System.Web.UI.HtmlControls;

使用System.Web.SessionState;

使用System.Diagnostics;

使用System.IO;









公共类操作方法

{





public operateMethod()

{

}

public static string ffmpegtool = ConfigurationManager.AppSettings [ffmpeg];

public static string upFile =upfile /;

public static string imgFile =imgFile /;

公共静态字符串playFile =playFile /;

public static string sizeOfImg = ConfigurationManager.AppSettings [imgSize];

public static string widthOfFile = ConfigurationManager.AppSettings [widthSize];

public static string heightOfFile = ConfigurationManager.AppSettings [heightSize];





public static bool changeVideoType(string fileName,string playFile ,string imgFile)

{

string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(../)+ ffmpegtool;

string Name = System.Web.HttpContext.Current.Server.MapPath(../)+ upFile +/+ fileName;

if((!System.IO.File .Exists(ffmpeg))||(!System.IO.File.Exists(Name)))

{

返回false;

}

string flv_file = playFile;

处理pss = new Process();

pss.StartInfo.CreateNoWindow = false;

pss.StartInfo.FileName = ffmpeg;

pss.StartInfo.Arguments = - i+ Name + - ab 128 -ar 22050 -qscale 6 -r 29.97 -s+ widthOfFile +x + heightOfFile ++ flv_file;



尝试

{

pss.Start();

while(!pss.HasExited)

{

继续;

}



catchImg(名称,imgFile);

System.Threading.Thread.Sleep(4000) ;

if(!File.Exists(imgFile))

{

File.Copy(System.Web.HttpContext.Current.Server。 MapPath(../)+imgHead\\default.gif,imgFile);

}



返回true ;

}

catch

{

返回false;

}



}

公共静态字符串GetFlashText(字符串网址)

{

url = player.swf?fileName =+ url;

string str =< object classid ='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'width ='452'height ='360 'id ='index'name ='index'>< param name =allowScriptAccessvalue =always/>< param name =movievalue =+ & lt; br =mode =hold& gt; =url =+ ==/>< embed src ='+

url +'id ='index1'name ='index1'type ='application / x-shockwave-flash'swLiveConnect = true allowScriptAccess ='always'width ='452'height ='360'>< /嵌入>< / object>;

返回str;

}





//截断字符串

public static string interceptStr(string str,int len)

{

if(str.Length> ; len)

{

str = str.Substring(0,len)+......;

}

返回str;

}



public static string filtrateHtml(string str)

{

str = str.Trim();

str = str.Replace(',);

str = str.Replace (<,<);

str = str.Replace(>,>);

str = str.Replace (, );

str = str.Replace(\ n,
);

return str;

}

public static string resumeHtml(string str)

{

str = str.Trim();

str = str.Replace(,');

str = str.Replace(<,<);

str = str.Replace(>,>);

str = str.Replace( ,);

str = str.Replace(
,\ n);

retu rn str;

}









public static void catchImg(string fileName,string imgFile)

{

string ffmpeg = System.Web.HttpContext.Current.Server.MapPath(../ )+ ffmpegtool;

string flv_img = imgFile;

string FlvImgSize = sizeOfImg;

流程pss = new Process();

pss.StartInfo.FileName = ffmpeg;

pss.StartInfo.Arguments = - i+ fileName + - y -f image2 -ss 2 -vframes 1 -s+ FlvImgSize ++ flv_img;

pss.Start();



}

}









C#代码



使用System;

使用System.Data;

使用System.Configuration;

使用System.Collections;

使用System.Web;

使用System。 Web.Security;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI .WebControls.WebParts;

使用System.Web.UI.HtmlControls;

使用System.IO;



public partial class _Default:System.Web.UI.Page

{

string [] videoExtension = new string [] {flv,avi,wmv ,};

protected void Page_Load(object sender,EventArgs e)

{



}

protected void btnUpVideo_Click(object sender,EventArgs e)

{

string upFileName = fileupVideo.FileName;



if(thi s.fileupVideo.HasFile)

{

string upExtension = upFileName.Substring(upFileName.LastIndexOf(。)+ 1);

if(checkExtension(upExtension))

{



string upFilePath = Server.MapPath(UpFile)+ upFileName;



fileupVideo.SaveAs(upFilePath);



string saveName = DateTime.Now.ToString(yyyyMMddHHmmssffff);



string playFile =playFile /+ saveName +。flv;



string imgFile =imgFile /+ saveName +.jpg;



试试

{

if(upExtension ==flv)

{

File.Copy(fileupVideo.PostedFile.FileName,Server.MapPath(../\"+ playFile));

operateMethod.catchImg(Server.MapPath( ../+ playFile),Server.MapPath(../+ imgFile));

insertVideoInfo(playFile,imgFile);

}

else

{

if(operateMethod.changeVideoType(upFileName,Server.MapPath(../)+ playFile,Server.MapPath(。 ./)+ imgFile))

{

insertVideoInfo(playFile,imgFile);

File.Delete(upFilePath);

}

其他

{



File.Delete(upFilePath);

}

}

}

catch(exception ex)

{

Response.Write(ex.Message.ToString());

} < br $>
}

else {



}

}

}

private void insertVideoInfo(string playFileh,string imgFile)

{



string videoTitle = txtTitle .Text;

string videoContent = txtContent.Text;

string date = DateTime.Now.ToString();

string videoPath = playFileh;

string videoPicture = imgFile;

string videoType =;

int count = radBtnListType.Items.Co没有;

for(int i = 0;我<计数; i ++)

{

if(radBtnListType.Items [i] .Selected)

{

videoType = radBtnListType .Items [i] .Value;

休息;

}

}

string sqlInsert =insert into videoInfo值('+ videoTitle +','+ videoContent +','+ date +','+ videoPath +','+ videoPicture +','+ videoType +' ,'','','','','');

if(operateData.execSql(sqlInsert))

{



string sqlUpd =update userInfo set sumMark = sumMark + 100 where userName ='+ videoTitle +';

operateData.execSql(sqlUpd); < br $>


}



}



私人bool checkExtension(字符串扩展名)

{

bool strReturn = false;

foreach(在此.videoExtension中的字符串var)

{

if(var == extension)

{

strReturn = true;休息;

}

}

返回strReturn;





}





}





App_Code

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
using System.Diagnostics;
using System.IO;




public class operateMethod
{


public operateMethod()
{
}
public static string ffmpegtool = ConfigurationManager.AppSettings["ffmpeg"];
public static string upFile = "upfile/";
public static string imgFile = "imgFile/";
public static string playFile = "playFile/";
public static string sizeOfImg = ConfigurationManager.AppSettings["imgSize"];
public static string widthOfFile = ConfigurationManager.AppSettings["widthSize"];
public static string heightOfFile = ConfigurationManager.AppSettings["heightSize"];


public static bool changeVideoType(string fileName, string playFile, string imgFile)
{
string ffmpeg= System.Web.HttpContext.Current.Server.MapPath("../") + ffmpegtool;
string Name = System.Web.HttpContext.Current.Server.MapPath("../") + upFile + "/" + fileName;
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(Name)))
{
return false;
}
string flv_file = playFile;
Process pss = new Process();
pss.StartInfo.CreateNoWindow = false;
pss.StartInfo.FileName = ffmpeg;
pss.StartInfo.Arguments = " -i " + Name + " -ab 128 -ar 22050 -qscale 6 -r 29.97 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file;

try
{
pss.Start();
while (!pss.HasExited)
{
continue;
}

catchImg(Name, imgFile);
System.Threading.Thread.Sleep(4000);
if (!File.Exists(imgFile))
{
File.Copy(System.Web.HttpContext.Current.Server.MapPath("../") + "imgHead\\default.gif", imgFile);
}

return true;
}
catch
{
return false;
}

}
public static string GetFlashText(string url)
{
url = "player.swf?fileName=" + url;
string str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='452' height='360' id='index' name='index'><param name="allowScriptAccess" value="always" /><param name="movie" value="" +&lt;br="" mode="hold" &gt;="" url="" +="" ""="" /><embed src='" +
url + "' id='index1' name='index1' type='application/x-shockwave-flash' swLiveConnect=true allowScriptAccess='always' width='452' height='360'></embed></object>";
return str;
}


//truncate the string
public static string interceptStr(string str, int len)
{
if (str.Length > len)
{
str = str.Substring(0,len)+ "...";
}
return str;
}

public static string filtrateHtml(string str)
{
str = str.Trim();
str = str.Replace("'", """);
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace(" ", " ");
str = str.Replace("\n", "
");
return str;
}
public static string resumeHtml(string str)
{
str = str.Trim();
str = str.Replace(""", "'");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace(" ", " ");
str = str.Replace("
", "\n");
return str;
}




public static void catchImg(string fileName,string imgFile)
{
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath("../") + ffmpegtool;
string flv_img = imgFile;
string FlvImgSize = sizeOfImg;
Process pss = new Process();
pss.StartInfo.FileName = ffmpeg;
pss.StartInfo.Arguments = " -i " + fileName + " -y -f image2 -ss 2 -vframes 1 -s " + FlvImgSize + " " + flv_img;
pss.Start();

}
}




C# code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
string[] videoExtension = new string[] { "flv", "avi", "wmv", };
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUpVideo_Click(object sender, EventArgs e)
{
string upFileName = fileupVideo.FileName;

if(this.fileupVideo.HasFile)
{
string upExtension = upFileName.Substring(upFileName.LastIndexOf(".")+1);
if (checkExtension(upExtension))
{

string upFilePath = Server.MapPath("UpFile") + upFileName;

fileupVideo.SaveAs(upFilePath);

string saveName = DateTime.Now.ToString("yyyyMMddHHmmssffff");

string playFile = "playFile/" + saveName + ".flv";

string imgFile = "imgFile/" + saveName + ".jpg";

try
{
if (upExtension == "flv")
{
File.Copy(fileupVideo.PostedFile.FileName,Server.MapPath("../"+playFile));
operateMethod.catchImg(Server.MapPath("../" + playFile), Server.MapPath("../" + imgFile));
insertVideoInfo(playFile, imgFile);
}
else
{
if (operateMethod.changeVideoType(upFileName, Server.MapPath("../") + playFile, Server.MapPath("../") + imgFile))
{
insertVideoInfo(playFile,imgFile);
File.Delete(upFilePath);
}
else
{

File.Delete(upFilePath);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
else {

}
}
}
private void insertVideoInfo(string playFileh, string imgFile)
{

string videoTitle = txtTitle.Text;
string videoContent = txtContent.Text;
string date = DateTime.Now.ToString();
string videoPath = playFileh;
string videoPicture = imgFile;
string videoType = "";
int count = radBtnListType.Items.Count;
for (int i = 0; i < count; i++)
{
if (radBtnListType.Items[i].Selected)
{
videoType = radBtnListType.Items[i].Value;
break;
}
}
string sqlInsert = "insert into videoInfo values('" + videoTitle + "','" + videoContent + "','" + date + "','" + videoPath + "','" + videoPicture + "','" + videoType + "','','','','','')";
if (operateData.execSql(sqlInsert))
{

string sqlUpd = " update userInfo set sumMark=sumMark+100 where userName='" + videoTitle + "'";
operateData.execSql(sqlUpd);

}

}

private bool checkExtension(string extension)
{
bool strReturn = false;
foreach (string var in this.videoExtension)
{
if (var == extension)
{
strReturn = true; break;
}
}
return strReturn;


}


}

推荐答案

这篇关于即时尝试在asp.net上传视频,但正在帮我一些朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆