17,741
社区成员
发帖
与我相关
我的任务
分享
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="550" height="100" id="fileUpload" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="fileUpload.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent">
<PARAM NAME=FlashVars VALUE='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'>
<embed src="fileUpload.swf"
FlashVars='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'
quality="high" wmode="transparent" width="550" height="100"
name="fileUpload" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
protected void Page_Load(object sender, EventArgs e)
{
string jscript = "function UploadComplete(){";
jscript += string.Format("__doPostBack('{0}','');", LinkButton1.ClientID.Replace("_", "$"));
jscript += "};";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
}
protected string GetFlashVars()
{
return "?" + Server.UrlEncode(Request.QueryString.ToString());
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//这里面不知道怎么写,就是获取上传的文件名或者在这里面判断,如果获取cc.rmvb的话,
//我就可以这样写了
string avi = "cc.rmvb";
string c = avi.Substring(avi.LastIndexOf("."));
if(c!=".avi")
{
弹出警告
}else
{
弹出上传成功
}
现在的问题,就是怎么获取???请各位大侠帮个忙撒!
}
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.IO;
public class Upload : IHttpHandler
{
public Upload()
{
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
string tempFile = context.Request.PhysicalApplicationPath;
for (int j = 0; j < context.Request.Files.Count; j++)
{
HttpPostedFile uploadFile = context.Request.Files[j];
string avi = uploadFile.FileName;
string c = avi.Substring(avi.LastIndexOf("."));
if (c!= ".avi")
{
//在这里面写了,可不弹出这句话,但这句话进入了
HttpContext.Current.Response.Write("<Script>alert('上传视频格式只能是avi!');</Script>");
// return;
}
else
{
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "images/video\\", uploadFile.FileName));
}
}
}
}
HttpContext.Current.Response.Write(" ");
}
#endregion
}
protected void Page_Load(object sender, EventArgs e)
{
string jscript = "function UploadComplete(){";
jscript += string.Format("__doPostBack('{0}','');", LinkButton1.ClientID.Replace("_", "$"));
jscript += "};";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
}
protected string GetFlashVars()
{
return "?" + Server.UrlEncode(Request.QueryString.ToString());
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
string filename = Upload.msgs;
string format = filename.Substring(filename.LastIndexOf("."));
if (format != ".flv")
{
this.lblMes.Text = "只支持flv格式的视频!";
// Response.Write("<script>alert('只支持flv格式的视频!');</script>");
}
else
{
this.lblMes.Text = "上传成功!";
//Response.Write("<script>alert('上传成功!');</script>");
}
}
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.IO;
public class Upload : IHttpHandler
{
public Upload()
{
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public static string msgs = string.Empty;
public void ProcessRequest(HttpContext context)
{
string c = string.Empty;
HttpPostedFile uploadFile = null;
string filename=null;
string tempFile = null;
if (context.Request.Files.Count > 0)
{
tempFile = context.Request.PhysicalApplicationPath;
for (int j = 0; j < context.Request.Files.Count; j++)
{
uploadFile = context.Request.Files[j];
filename= uploadFile.FileName;
c = filename.Substring(filename.LastIndexOf("."));
}
}
string str = string.Empty;
msgs = filename;
if (c != ".flv")
{
return;
}
else
{
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "images/video\\", uploadFile.FileName));
}
}
HttpContext.Current.Response.Write(" ");
}
#endregion
}