<%@ Page language="c#" src="UPLOAD_CS.aspx.cs" AutoEventWireup="false" Inherits="HowTos.MultipleImageUpdate.UPLOAD" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>:::i7land无组件多文件上传程序 ::: </title>
</HEAD>
<body>
<center>
<form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
<h3>多文件上传<hr><br>为保证服务器和网站的安全,禁止上传任何.COM或.DLL文件,但允许你上传任何gif、jpg、swf、asp、aspx、htm、html、js、css等网络文件</h3>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><STRONG>:: </STRONG>
<asp:LinkButton id="LinkButton1" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small">上传</asp:LinkButton> <STRONG>::
</STRONG> <A href="javascript:document.forms[0].reset()" id="LinkButton2" style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana">
重置</A> <STRONG>::</STRONG></P>
<P>
<asp:Label id="Label1" runat="server" Font-Names="verdana" Font-Bold="True" Font-Size="XX-Small" Width="400px" BorderStyle="None" BorderColor="White"></asp:Label></P>
<P> </P>
</form>
</center>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>:::i7land无组件多文件上传程序 ::: </title>
</HEAD>
<body>
<center>
<form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
<h3>多文件上传<hr><br>为保证服务器和网站的安全,禁止上传任何.COM或.DLL文件,但允许你上传任何gif、jpg、swf、asp、aspx、htm、html、js、css等网络文件</h3>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><INPUT type="file" runat="server" size="50"></P>
<P><STRONG>:: </STRONG>
<asp:LinkButton id="LinkButton1" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small">上传</asp:LinkButton> <STRONG>::
</STRONG> <A href="javascript:document.forms[0].reset()" id="LinkButton2" style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana">
重置</A> <STRONG>::</STRONG></P>
<P>
<asp:Label id="Label1" runat="server" Font-Names="verdana" Font-Bold="True" Font-Size="XX-Small" Width="400px" BorderStyle="None" BorderColor="White"></asp:Label></P>
<P> </P>
</form>
</center>
</body>
</HTML>
程序代码:
这是( UPLOAD_CS.aspx.cs ):
namespace HowTos.MultipleImageUpdate
{
public class UPLOAD : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
#region User Defined Code
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(System.Object sender, System.EventArgs e)
{
if ( this.IsPostBack )
this.SaveImages();
}
private System.Boolean SaveImages() {
//loop through the files uploaded
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;
//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("文件已成功上传:其中.gif.swf文件上传到gifs目录中,网页文件上传到web目录中,.jpg文件上传到jpgs目录中<br>";
try
{
for ( System.Int32 _iFile = 0; _iFile < _files.Count; _iFile ++ )
{
// Check to make sure the uploaded file is a jpg or gif
System.Web.HttpPostedFile _postedFile = _files[_iFile];
System.String _fileName, _fileExtension;
_fileName = System.IO.Path.GetFileName(
_postedFile.FileName);
_fileExtension = System.IO.Path.GetExtension(
_fileName);
if ( _fileExtension == ".bmp" ||_fileExtension==".BMP"||_fileExtension == ".gif" ||_fileExtension==".GIF" ||_fileExtension==".swf" ||_fileExtension==".SWF" )
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles/images" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if ( _fileExtension == ".jpg" ||_fileExtension==".JPG"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles/images" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if ( _fileExtension == ".asp" ||_fileExtension==".ASP" ||_fileExtension==".aspx" ||_fileExtension==".ASPX" ||_fileExtension==".htm" ||_fileExtension==".HTM" ||_fileExtension==".HTML" ||_fileExtension==".html" ||_fileExtension==".cs" ||_fileExtension==".CS" ||_fileExtension==".txt" ||_fileExtension==".TXT" ||_fileExtension==".RAR" ||_fileExtension==".rar" ||_fileExtension==".zip" ||_fileExtension==".ZIP" ||_fileExtension==".INC" ||_fileExtension==".inc" ||_fileExtension==".xml" ||_fileExtension==".XML" ||_fileExtension==".MDB" ||_fileExtension==".mdb" ||_fileExtension==".JS" ||_fileExtension==".js" ||_fileExtension==".vb" ||_fileExtension==".VB" ||_fileExtension==".css" ||_fileExtension==".CSS" ||_fileExtension==".CONFIG" ||_fileExtension==".config" ||_fileExtension == ".exe" ||_fileExtension==".EXE"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if(_fileExtension==".COM" ||_fileExtension==".com" ||_fileExtension==".dll" ||_fileExtension==".DLL"
continue;
else {
_message.Append(_fileName + " <font color="red">上传失败,可能是文件格式不对!本系统为保证网站和服务器的安全,禁止上传任何.COM或.DLL文件</font> <BR>";
}
}
Label1.Text = _message.ToString();
return true;
}
catch ( System.Exception Ex )
{
Label1.Text = Ex.Message ;
return false;
}
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(System.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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
namespace HowTos.MultipleImageUpdate
{
public class UPLOAD : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
#region User Defined Code
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(System.Object sender, System.EventArgs e)
{
if ( this.IsPostBack )
this.SaveImages();
}
private System.Boolean SaveImages() {
//loop through the files uploaded
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;
//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("文件已成功上传:其中.gif.swf文件上传到gifs目录中,网页文件上传到web目录中,.jpg文件上传到jpgs目录中<br>";
try
{
for ( System.Int32 _iFile = 0; _iFile < _files.Count; _iFile ++ )
{
// Check to make sure the uploaded file is a jpg or gif
System.Web.HttpPostedFile _postedFile = _files[_iFile];
System.String _fileName, _fileExtension;
_fileName = System.IO.Path.GetFileName(
_postedFile.FileName);
_fileExtension = System.IO.Path.GetExtension(
_fileName);
if ( _fileExtension == ".bmp" ||_fileExtension==".BMP"||_fileExtension == ".gif" ||_fileExtension==".GIF" ||_fileExtension==".swf" ||_fileExtension==".SWF" )
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles/images" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if ( _fileExtension == ".jpg" ||_fileExtension==".JPG"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles/images" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if ( _fileExtension == ".asp" ||_fileExtension==".ASP" ||_fileExtension==".aspx" ||_fileExtension==".ASPX" ||_fileExtension==".htm" ||_fileExtension==".HTM" ||_fileExtension==".HTML" ||_fileExtension==".html" ||_fileExtension==".cs" ||_fileExtension==".CS" ||_fileExtension==".txt" ||_fileExtension==".TXT" ||_fileExtension==".RAR" ||_fileExtension==".rar" ||_fileExtension==".zip" ||_fileExtension==".ZIP" ||_fileExtension==".INC" ||_fileExtension==".inc" ||_fileExtension==".xml" ||_fileExtension==".XML" ||_fileExtension==".MDB" ||_fileExtension==".mdb" ||_fileExtension==".JS" ||_fileExtension==".js" ||_fileExtension==".vb" ||_fileExtension==".VB" ||_fileExtension==".css" ||_fileExtension==".CSS" ||_fileExtension==".CONFIG" ||_fileExtension==".config" ||_fileExtension == ".exe" ||_fileExtension==".EXE"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"../uploadfiles" + _fileName);
_message.Append(_fileName + "<BR>";
}
else if(_fileExtension==".COM" ||_fileExtension==".com" ||_fileExtension==".dll" ||_fileExtension==".DLL"
continue;
else {
_message.Append(_fileName + " <font color="red">上传失败,可能是文件格式不对!本系统为保证网站和服务器的安全,禁止上传任何.COM或.DLL文件</font> <BR>";
}
}
Label1.Text = _message.ToString();
return true;
}
catch ( System.Exception Ex )
{
Label1.Text = Ex.Message ;
return false;
}
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(System.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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}