多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
来源:互联网 发布:周小平其人知乎 编辑:程序博客网 时间:2024/06/05 17:50
一.多文件上传【客户端处理脚本的例子】
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<script>
function mCreateFile(obj){
var eF
var mName
mFileName.innerHTML=""
if (obj.id=="File") {
for (i=0;i<mFile.children.length-1;i++)
{
if (mFile.children[i].value=="") {
mFile.removeChild(mFile.children[i])
}
else
{
mName=mFile.children[i].value.split("")
mFileName.innerHTML+="<div id=NameDetail title='"+mName[mName.length-1]+"'>"+mName[mName.length-1]+"</div>"
}
}
mstatus.innerHTML="总共有 <b>"+(mFile.children.length-1)+"</b> 个文件等待上传"
}
if (obj.id=="File_New") {
eF=document.createElement('<input type="file" name="File" size="23" id=File_New onpropertychange="mCreateFile(this)">')
mFile.appendChild(eF)
obj.id="File"
}
}
</script>
<style>
table{
FILTER: progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#999999,strength=3);
}
input{
border:1px soild #000000;
font-family:Verdana,Arial,宋体;
font-size:12px;
padding:2px;
}
#mTD{
LINE-HEIGHT: 24px;
}
#mFile{
width:203px;
float:left;
|
#mFileName{
float:right;
width:182px;
}
#NameDetail{
overflow:hidden;
width:176px;
color:#000000;
font-family:Verdana,Arial,宋体;
font-size:12px;
cursor:default;
height:22px;
}
#mstatus{
font-size:12px;
color:#ff0000;
}
</style>
</head>
<body>
<form name=frm method=post>
<div align="center">
<table border="1" width="420" style="border-collapse: collapse" bordercolor="#0066cc" cellpadding="4" bgcolor="#D0F0FF">
<tr>
<td bgcolor="#3399FF" height="26" align="center"><font color="#FFFFFF" size="3"><b>添加附件</b></font></td>
</tr>
<tr>
<td id=mTD>
<div id=mFile><input type="file" name="File" size="23" id=File_New onpropertychange="mCreateFile(this)"></div>
<div id=mFileName></div>
<div id=mstatus>总共有 <b>0</b> 个文件等待上传</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>后台代码:CS
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<script>
function mCreateFile(obj){
var eF
var mName
mFileName.innerHTML=""
if (obj.id=="File") {
for (i=0;i<mFile.children.length-1;i++)
{
if (mFile.children[i].value=="") {
mFile.removeChild(mFile.children[i])
}
else
{
mName=mFile.children[i].value.split("")
mFileName.innerHTML+="<div id=NameDetail title='"+mName[mName.length-1]+"'>"+mName[mName.length-1]+"</div>"
}
}
mstatus.innerHTML="总共有 <b>"+(mFile.children.length-1)+"</b> 个文件等待上传"
}
if (obj.id=="File_New") {
eF=document.createElement('<input type="file" name="File" size="23" id=File_New onpropertychange="mCreateFile(this)">')
mFile.appendChild(eF)
obj.id="File"
}
}
</script>
<style>
table{
FILTER: progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#999999,strength=3);
}
input{
border:1px soild #000000;
font-family:Verdana,Arial,宋体;
font-size:12px;
padding:2px;
}
#mTD{
LINE-HEIGHT: 24px;
}
#mFile{
width:203px;
float:left;
|
#mFileName{
float:right;
width:182px;
}
#NameDetail{
overflow:hidden;
width:176px;
color:#000000;
font-family:Verdana,Arial,宋体;
font-size:12px;
cursor:default;
height:22px;
}
#mstatus{
font-size:12px;
color:#ff0000;
}
</style>
</head>
<body>
<form name=frm method=post>
<div align="center">
<table border="1" width="420" style="border-collapse: collapse" bordercolor="#0066cc" cellpadding="4" bgcolor="#D0F0FF">
<tr>
<td bgcolor="#3399FF" height="26" align="center"><font color="#FFFFFF" size="3"><b>添加附件</b></font></td>
</tr>
<tr>
<td id=mTD>
<div id=mFile><input type="file" name="File" size="23" id=File_New onpropertychange="mCreateFile(this)"></div>
<div id=mFileName></div>
<div id=mstatus>总共有 <b>0</b> 个文件等待上传</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>后台代码:CS
二.简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
前台代码:ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Album_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>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
<asp:Image ID="Image1" runat="server" Height="100px" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
<!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>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
<asp:Image ID="Image1" runat="server" Height="100px" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
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;
public partial class Album_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Image1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
string filename = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string[] myfile = filename.Split('.');
string dotname = myfile[myfile.Length - 1].ToString().ToLower();
string type = FileUpload1.PostedFile.ContentType;
string type2 = filename.Substring(filename.LastIndexOf(".") + 1);
string imgpath = Server.MapPath("~/Upimg") + "/";
string filepath = Server.MapPath("~/Upfile") + "/";
string folder = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
if (type2 == "jpg" || type2 == "gif")
{
Image1.Visible = true;
if (!System.IO.Directory.Exists(imgpath + folder))
{//自动生成文件夹
System.IO.Directory.CreateDirectory(imgpath + folder);
}
Random myrdn = new Random();//产生随机数
//日期,时间,随机数和后缀名
string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + myrdn.Next(10000).ToString() + "." + dotname;
FileUpload1.SaveAs(imgpath + folder + "/" + newfilename);
string wpath = "~/Upimg/" + folder + "/" + newfilename;
Image1.ImageUrl = wpath;
//FileUpload1.SaveAs(ipath);
Label1.Text = "原始文件名" + filename + "<br>存储文件名:" + newfilename + "<br>文件大小" + size + "<br>文件类型" + type2 + "<br>文件后缀" + type + "<br>文件虚拟路径" + wpath;
}
else
{
if (!System.IO.Directory.Exists(filepath + folder))
{//自动生成文件夹
System.IO.Directory.CreateDirectory(filepath + folder);
}
Random myrdn = new Random();//产生随机数
//日期,时间,随机数和后缀名
string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + myrdn.Next(10000).ToString() + "." + dotname;
Image1.Visible = false;
string wpath = "Upfile/" + folder + newfilename;
FileUpload1.SaveAs(filepath + folder + "/" + newfilename);
Label1.Text = "原始文件名" + filename + "<br>存储文件名:" + newfilename + "<br>文件大小" + size + "<br>文件类型" + type2 + "<br>文件后缀" + type + "<br>文件虚拟路径" + wpath;
}
}
}
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;
public partial class Album_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Image1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
string filename = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string[] myfile = filename.Split('.');
string dotname = myfile[myfile.Length - 1].ToString().ToLower();
string type = FileUpload1.PostedFile.ContentType;
string type2 = filename.Substring(filename.LastIndexOf(".") + 1);
string imgpath = Server.MapPath("~/Upimg") + "/";
string filepath = Server.MapPath("~/Upfile") + "/";
string folder = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
if (type2 == "jpg" || type2 == "gif")
{
Image1.Visible = true;
if (!System.IO.Directory.Exists(imgpath + folder))
{//自动生成文件夹
System.IO.Directory.CreateDirectory(imgpath + folder);
}
Random myrdn = new Random();//产生随机数
//日期,时间,随机数和后缀名
string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + myrdn.Next(10000).ToString() + "." + dotname;
FileUpload1.SaveAs(imgpath + folder + "/" + newfilename);
string wpath = "~/Upimg/" + folder + "/" + newfilename;
Image1.ImageUrl = wpath;
//FileUpload1.SaveAs(ipath);
Label1.Text = "原始文件名" + filename + "<br>存储文件名:" + newfilename + "<br>文件大小" + size + "<br>文件类型" + type2 + "<br>文件后缀" + type + "<br>文件虚拟路径" + wpath;
}
else
{
if (!System.IO.Directory.Exists(filepath + folder))
{//自动生成文件夹
System.IO.Directory.CreateDirectory(filepath + folder);
}
Random myrdn = new Random();//产生随机数
//日期,时间,随机数和后缀名
string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + myrdn.Next(10000).ToString() + "." + dotname;
Image1.Visible = false;
string wpath = "Upfile/" + folder + newfilename;
FileUpload1.SaveAs(filepath + folder + "/" + newfilename);
Label1.Text = "原始文件名" + filename + "<br>存储文件名:" + newfilename + "<br>文件大小" + size + "<br>文件类型" + type2 + "<br>文件后缀" + type + "<br>文件虚拟路径" + wpath;
}
}
}
- 多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
- 多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
- 文件上传[多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)]
- 文件上传[多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)]【深海原创】
- 简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
- 文件上传实例(文件上传,自动重命名,自动添加文件夹)
- 文件上传实例(文件上传,自动重命名,自动添加文件夹)
- C#文件上传实例(文件上传,自动重命名,自动添加文件夹)
- 文件上传实例(文件上传,自动重命名,自动添加文件夹)
- FCKeditor V2.x上传文件自动重命名
- FCKeditor V2.x上传文件自动重命名
- Asp.net文件上传 重命名 以及自动创建上传目录
- 上传文件时自动生成文件夹
- psftp 自动上传文件
- HttpUrlConnection 自动上传文件
- ahk自动上传文件的脚本实例
- 定期自动重命名文件并上传到ftp然后删除
- wordpress上传文件重命名
- 网页中添加播放器播放视频文件与网页增加背景音乐示例
- about PCB
- 如何禁用注册表自动修改
- CSS实现图片阴影效果三部曲
- テープル「T074」中に特殊仕訳データはどういうふうに生じたか?
- 多文件上传与简单操作文件上传实例(文件上传,自动重命名,自动添加文件夹)
- Windows CE 6.0 安装顺序
- 云计算
- 预防按钮的多次点击【恶意刷新】
- SQLyog查询器里面正常显示带中文的sql语句的办法
- 从零开始教您创建一个华丽高档的网页
- DNS 加载区域时的 9002错误解决方法(事件ID4521)
- エラー メッセージ "0x800ccc79" が表示され、Outlook Express でメールを送信できない
- jxl 写Excel