Html上传多个文件

1.页面

<span style="float: left;text-align:left;" id="spanFileList">                                 <input type="button" value="添加附件" onclick="AddFiles()" style="margin-top: 5px; margin-left: 5px" /><br /> </span>

2.js

//添加附件

function AddFiles() {

var fileList = document.getElementById("spanFileList");

var file = document.createElement("input");

   file.setAttribute("type", "file")

file.setAttribute("name", "File")

file.setAttribute("runat", "server")

fileList.appendChild(file);

var br = document.createElement("br");

fileList.appendChild(br);

}

3.后台代码

HttpFileCollection files = HttpContext.Current.Request.Files;                         string returnvalue = "";                         WebBindingList<ItemUploadFileModel> lst_file = new WebBindingList<ItemUploadFileModel>();                         string FilePath = CDHB.Common.Config.ConfigHelper.GetConfigString("FilePath");                         try                         {                             //取索引时从第三个开始取,                             for (int iFile = 0; iFile < files.Count; iFile++)                             {                                 HttpPostedFile uploadedFile = files[iFile];                                 if (!string.IsNullOrEmpty(uploadedFile.FileName))                                 {                                     string filename = uploadedFile.FileName;                                     string ext = filename.Substring(filename.LastIndexOf("."));                                     string filesize = "";                                     decimal n_filesize = 0;                                     if (uploadedFile.ContentLength > 0)                                     {                                         filesize = uploadedFile.ContentLength.ToString("n2") + "B";                                         if (uploadedFile.ContentLength > 1000)                                         {                                             n_filesize = Convert.ToDecimal(uploadedFile.ContentLength) / 1024;                                             filesize = n_filesize.ToString("n2") + "KB";                                         }                                         if (n_filesize > 1000)                                         {                                             n_filesize = n_filesize / 1024;                                             filesize = n_filesize.ToString("n2") + "M";                                         }                                         if (n_filesize > 1000)                                         {                                             n_filesize = n_filesize / 1024;                                             filesize = n_filesize.ToString("n2") + "G";                                         }                                         //获取当前年月份                                         string str = DateTime.Now.ToString("yyyyMM");                                         string strGui;                                         string strPath = HttpContext.Current.Server.MapPath(FilePath + str);                                         //如果源文件夹不存在则创建                                         if (!Directory.Exists(strPath))                                         {                                             Directory.CreateDirectory(strPath);                                         }                                         //重新赋文件名                                         string GuidName = Guid.NewGuid() + ext;                                         strGui = str + "/" + GuidName;                                         uploadedFile.SaveAs(Server.MapPath(FilePath + strGui));                                         returnvalue = filename + "|" + FilePath + strGui;

ItemUploadFileModel file = new ItemUploadFileModel(); ;                                         file.Id = Guid.NewGuid().ToString();                                         file.ItemId = rValue;                                         file.ItemFileName = filename;                                         file.ItemFileSize = filesize;                                         file.ItemFileSrc = FilePath + strGui;                                         file.UploadTime = DateTime.Now;                                         file.CreateTime = DateTime.Now;                                         lst_file.Add(file);                                     }

}                             }                                                        ExhibitionRegister.AddItemFile(lst_file);                         }

注:

1.js添加input是,name属性必须

2.form添加 enctype="multipart/form-data"  。

时间: 2024-10-10 22:46:35

Html上传多个文件的相关文章

struts2文件上传(单文件/批量添加)

单文件上传 1.导入上传需要jar包 2.建立UploadAction file是jsp页面的输入项的name相同,后面的两个属性的名称也是有规律的:(inputName+FileName/ContentType) 1 public class UploadAction extends ActionSupport{ 2 3 private static final long serialVersionUID = 1L; 4 private File file;//上传文件的本身 5 privat

Linux (rz、sz命令行)与本地电脑 命令行上传、下载文件

Linux 与本地电脑直接交互, 命令行上传.下载文件. 一.lrzsz命令行安装: 1.rpm安装:(链接: http://pan.baidu.com/s/1cBuTm2 密码: vijf) rpm -ivh lrzsz-0.12.20-22.1.x86_64.rpm 2.yum 安装: yum install lrzsz 二.命令使用: 1.发送到本地: sz 文件名 2.上传到服务器: rz -be 在弹出的框中选择文件,上传文件的用户和组是当前登录的用户

PSFTP自动登录SFTP服务器,批量自动上传上传下载指定文件

1.putty官方下载 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 下载安装版  putty-0.67-installer.msi 2.安装完成之后,打开putty安装目录,找到PSFTP.EXE,复制到新的文件夹 D:/Download 3.双击打开pstftp.exe,连接Linux服务器 4. 设置下载到windows的本地目录 5.psftp常用命令(操作服务端的文件则是Linux常用命令) lcd+路径

***使用PHP实现文件上传和多文件上传

http://www.365mini.com/page/php-upload-file.htm 在PHP程序开发中,文件上传是一个使用非常普遍的功能,也是PHP程序员的必备技能之一.值得高兴的是,在PHP中实现文件上传功能要比在Java.C#等语言中简单得多.下面我们结合具体的代码实例来详细介绍如何通过PHP实现文件上传和多文件上传功能. 要使用PHP实现文件上传功能,我们先来编写两个php文件:index.php和upload.php.其中,index.php页面用于提交文件上传的表单请求,u

SpringMVC实现单文件上传、多文件上传、文件列表显示、文件下载

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 本文详细讲解了SpringMVC实例单文件上传.多文件上传.文件列表显示.文件下载. 一.新建一个Web工程,导入相关的包 springmvc的包+commons-fileupload.jar+connom-io.jar+commons-logging,jar+jstl.jar+standard.jar 整个相关的包如下: 整个工程目录如下: 二.配置web.xml和SpringMVC文件

动态上传多个文件和解决文件的重名的问题(61)

动态上传多个文件 <form name="xx" action="<c:url value='/Up3Servlet'/>" method="post" enctype="multipart/form-data"> <table id="tb" border="1"> <tr> <td> File: </td> &l

struts文件上传(多文件)

第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

【转】每天一个linux命令(26):用SecureCRT来上传和下载文件

原文网址:http://www.cnblogs.com/peida/archive/2012/11/28/2793181.html 用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. 文件传输协议: 文件传输是数据交换的主要形式.在进行文件传输时,为使文件能被正确识别和传送,我们需要在两台计算机之间建立统一的传输协议.这个协议包括了文件的识别.传送的

Uploadify上传,可以上传多个文件,带有进度条,希望有所帮助!

原文:Uploadify上传,可以上传多个文件,带有进度条,希望有所帮助! 源代码下载:http://www.zuidaima.com/share/1550463502568448.htm 上传前 上传后 

如何在SecureCRT中给linux上传和下载文件 安装redis

首先建立文件 /download sz和rz命令无法用.则用以下1.和2.3步骤 需要上传或者下载,需要使用rz和sz命令.如果linux上没有这两个命令工具,则需要先安装.可以使用yum安装.运行命令yum install lrzsz.   安装完成后就可以使用rz命令上传本地的文件到linux平台.运行rz命令,会弹出选择文件的对话框.   选择需要上传的文件所在的文件夹,然后点击文件.然后再点击添加按钮,"发送的文件"框中就会显示需要上传的文件.点击确定按钮,就能完成上传. 解压