如何实现多个文件上传|如何上传多个文件

Ⅰ 如何上传多个文件一次

这个主要看媒介机制,一般选择文件的时候按住ctrl键然后选择,可以选择多个,但是有的不可以,因为网站机制限制一次只能传一个,有的网站也可以拖拽文件达到上传多个文件的目的

Ⅱ 论文指导如何上传多个文件

一般选择文件的时候按住ctrl键然后选择,可以选择多个,但是有的不可以,因为网站机制限制一次只能传一个,有的网站也可以拖拽文件达到上传多个文件

Ⅲ 多文件上传思路

给个例子吧:传几个地图文件到服务器1)aspx文件:<%@ Page language="c#" Codebehind="AddMap.aspx.cs" AutoEventWireup="false" Inherits="ZiFengLast.SystemSet.AddMap" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>MapAdmin</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="javaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <LINK href="../StyleSheet1.css" type="text/css" rel="stylesheet"> <script language="javascript"> function AddFile() { var rows=document.getElementById("rows").value; var cols=document.getElementById("cols").value; var FileList=document.getElementById("MyFile"); if(document.getElementById("MyFile").innerHTML.toString().length>200) { // alert(document.getElementById("MyFile").innerHTML.toString().length); FileList.innerHTML="<font class='TagTitle'><b>第1个地图:</b></font> <input style='WIDTH: 200px; HEIGHT: 22px' type='file' size='14' name='File'>"; } for(i=1;i<cols*rows;i++) { j=i+1; var str ='<font class="TagTitle"><b>第'+j+'个地图:</b></font> <input style="WIDTH: 200px; HEIGHT: 22px" type="file" size="14" name="File">'; FileList.insertAdjacentHTML("beforeEnd","<br>"); FileList.insertAdjacentHTML("beforeEnd",str); } }</script> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" encType="multipart/form-data" runat="server"> <FONT face="宋体"> <TABLE id="Table1" style="BORDER-RIGHT: #33cc66 2px groove; BORDER-TOP: #33cc66 2px groove; Z-INDEX: 101; LEFT: 136px; BORDER-LEFT: #33cc66 2px groove; BORDER-BOTTOM: #33cc66 2px groove; POSITION: absolute; TOP: 32px" width="500" align="center"> <TBODY> <TR height="20"> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="34%"></TD> </TR> <TR> <TD colSpan="2"></TD> <TD colSpan="4"><FONT class="WelcomeText" face="幼圆" color="#ff00ff" size="4">添加新地图</FONT></TD> </TR> <tr> <td class="TagTitle" align="right" colSpan="3"><b>请选择地图规格:</b></td> <td class="TagTitle" colSpan="2"><input id="rows" style="WIDTH: 32px; HEIGHT: 22px" type="text" size="1" value="1" runat="server" NAME="rows">行<input id="cols" style="WIDTH: 32px; HEIGHT: 22px" type="text" size="1" value="1" runat="server" NAME="cols">列</td> <td colSpan="2"><input style="WIDTH: 72px; HEIGHT: 22px" onclick="AddFile()" type="button" value="确定"></td> </tr> <TR> <TD class="TagTitle" align="right" width="33%" colSpan="3"><B>请选择地图文件:</B> </TD> <TD class="TagTitle" width="33%" colSpan="4"></TD> </TR> <tr> <td colSpan="7"> <p id="MyFile"><font class="TagTitle"><b>第1个地图:</b></font> <input style="WIDTH: 200px; HEIGHT: 22px" type="file" size="14" name="File"> </p> </td> <TR> <TD class="TagTitle" align="right" width="33%" colSpan="3"><B>请输入地图存储名称:</B> </TD> <TD class="TagTitle" align="left" width="33%" colSpan="4"><INPUT id="MapName" style="WIDTH: 128px; HEIGHT: 22px" type="text" size="16" name="Password" runat="server"> <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" CssClass="TagTitle" ErrorMessage="地图名不能为空" Font-Names="微软雅黑" Font-Size="X-Small" ControlToValidate="MapName"></asp:requiredfieldvalidator></TD> </TR> <TR> <TD class="TagTitle" style="HEIGHT: 29px" align="right" width="33%" colSpan="3"><B><asp:label id="Msg0" runat="server"></asp:label></B> </TD> <TD class="TagTitle" style="HEIGHT: 29px" width="33%" colSpan="4"><span class="ErrorMessage" id="OutputSpan" runat="server"><asp:label id="Msg" runat="server"></asp:label></span></TD> </TR> <TR> <TD width="11%"></TD> <TD width="11%"></TD> <TD width="22%" colSpan="4"> <asp:button id="SubmitButton" runat="server" Font-Names="微软雅黑" Font-Size="X-Small" Text="提交" Height="26px" Width="60px"></asp:button><INPUT id="CancelButton" style="FONT-SIZE: x-small; WIDTH: 60px; FONT-FAMILY: 微软雅黑; HEIGHT: 26px" type="reset" value="清除" name="CancelButton"></TD> <TD width="34%"> </TD> </TR> </TBODY> </TABLE> <TABLE id="Table2" style="Z-INDEX: 102; LEFT: 136px; WIDTH: 491px; POSITION: absolute; TOP: 8px; HEIGHT: 26px" width="491" align="center"> <TR> <TD class="TagTitle"><A href="DeleteMap.aspx"><FONT class="WelcomeText" face="幼圆">删除已有地图</FONT></A></TD> </TR> </TABLE> </FONT> </form> </TR></TBODY></TABLE></FONT> </body></HTML>2)后台cs文件:关键是使用Request.Files获取刚上传的文件:using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Configuration;namespace ZiFengLast.SystemSet{ /// <summary> /// MapAdmin 的摘要说明。 /// </summary> public class AddMap : System.Web.UI.Page { protected System.Web.UI.WebControls.Button SubmitButton; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2; protected System.Web.UI.HtmlControls.HtmlGenericControl OutputSpan; protected System.Web.UI.WebControls.Label Msg; protected System.Web.UI.WebControls.Label Msg0; protected System.Data.SqlClient.SqlConnection MapConn; protected System.Data.SqlClient.SqlCommand MapComm; protected System.Web.UI.HtmlControls.HtmlInputText rows; protected System.Web.UI.HtmlControls.HtmlInputText cols; protected System.Web.UI.HtmlControls.HtmlInputText MapName;private void Page_Load(object sender, System.EventArgs e) {// 在此处放置用户代码以初始化页面}#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 – 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.MapConn = new System.Data.SqlClient.SqlConnection(); this.MapComm = new System.Data.SqlClient.SqlCommand(); this.SubmitButton.Click += new System.EventHandler(this.SubmitButton_Click); // // MapConn // this.MapConn.ConnectionString =System.Configuration.ConfigurationSettings.AppSettings["sqlMap"]; // // MapComm // this.MapComm.Connection = this.MapConn; this.Load += new System.EventHandler(this.Page_Load); } #endregion private void SubmitButton_Click(object sender, System.EventArgs e) { try { HttpFileCollection file=Request.Files; System.Text.StringBuilder FileNameArray=new System.Text.StringBuilder(); string SaveName=this.MapName.Value.Trim(); string FileExtension0=System.IO.Path.GetExtension(System.IO.Path.GetFileName(file[0].FileName)); for(int i=0;i<file.Count;i++) { HttpPostedFile PostFile=file[i]; string FileName=System.IO.Path.GetFileName(PostFile.FileName); FileName.Replace(";","_"); string FileExtension=System.IO.Path.GetExtension(FileName); string ContentType=PostFile.ContentType.ToString(); string LastSaveName=SaveName+(i+1).ToString()+FileExtension; PostFile.SaveAs(Request.MapPath("../Map/"+LastSaveName)); FileNameArray.Append(LastSaveName); FileNameArray.Append(";"); } this.MapComm.CommandText="Select [Map].* from [Map] where MapName='"+SaveName+"'"; this.MapConn.Open(); System.Data.SqlClient.SqlDataReader rd=this.MapComm.ExecuteReader(); if(rd.Read()) { this.MapConn.Close(); this.MapConn.Dispose(); this.MapComm.Dispose(); rd.Close(); Msg0.Text="<font class=ErrorMessage>上传文件失败!</font>"; Msg.Text="<font class=ErrorMessage>已有该地图名称,请指定另外的名称</font>"; } else { rd.Close(); this.MapComm.CommandText="insert into [Map](MapName,MapRows,MapCols,MapFileNames) Values('"+SaveName+"',"+int.Parse(rows.Value)+","+int.Parse(cols.Value)+",'"+FileNameArray+"')"; //Response.Write(MapComm.CommandText); this.MapComm.ExecuteNonQuery(); this.MapConn.Close(); this.MapConn.Dispose(); this.MapComm.Dispose(); } Msg0.Text="<font class=ErrorMessage>上传文件成功!</font>"; Msg.Text="<font class=ErrorMessage>共计上传文件"+file.Count.ToString()+"个"+"<br>"+FileNameArray+"</font>"; } catch(Exception ee) { Msg0.Text="<font class=ErrorMessage>上传文件失败!</font>"; Msg.Text="<font class=ErrorMessage>"+ee.ToString()+"</font>"; } }}}

Ⅳ java实现多文件上传

即使再多文件也是通过的单个文件逐次上传的(zip等压缩包实际上是一个文件)。实现思路就是将多个文件循环进行上传,上传方法举例:/*** 上传文件** @param fileName* @param plainFilePath 文件路径路径* @param filepath* @return * @throws Exception*/public static String fileUploadByFtp(String plainFilePath, String fileName, String filepath) throws Exception {FileInputStream fis = null;ByteArrayOutputStream bos = null;FTPClient ftpClient = new FTPClient();String bl = "false";try {fis = new FileInputStream(plainFilePath);bos = new ByteArrayOutputStream(fis.available());byte[] buffer = new byte[1024];int count = 0;while ((count = fis.read(buffer)) != -1) {bos.write(buffer, 0, count);}bos.flush();Log.info("加密上传文件开始");Log.info("连接远程上传服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);FTPFile[] fs;fs = ftpClient.listFiles();for (FTPFile ff : fs) {if (ff.getName().equals(filepath)) {bl="true";ftpClient.changeWorkingDirectory("/"+filepath+"");}}Log.info("检查文件路径是否存在:/"+filepath);if("false".equals(bl)){ViewUtil.dataSEErrorPerformedCommon( "查询文件路径不存在:"+"/"+filepath);return bl;}ftpClient.setBufferSize(1024);ftpClient.setControlEncoding("GBK");// 设置文件类型(二进制)ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);ftpClient.storeFile(fileName, fis);Log.info("上传文件成功:"+fileName+"。文件保存路径:"+"/"+filepath+"/");return bl;} catch (Exception e) {throw e;} finally {if (fis != null) {try {fis.close();} catch (Exception e) {Log.info(e.getLocalizedMessage(), e);}}if (bos != null) {try {bos.close();} catch (Exception e) {Log.info(e.getLocalizedMessage(), e);}}}}备注:只需要修改上传的服务器地址、用户名、密码即可进行服务器访问上传。根据实际需要修改即可。

Ⅳ php如何实现一次性上传多个文件

<?php $max_files=5; //最多上传文件的个数,与 up.htm 中的 input file 控件的个数相同$up_ok_files=0; //成功上传的文件个数$up_folder="ups"; //保存上传文件的目标文件夹if(isset($_FILES['myfile'])){ //由于 $_FILES['myfile'] 是个数组,所以需要使用循环遍历 for($i=0;$i<$max_files;$i++){ //如果未出错 if($_FILES['myfile']['error'][$i]==0){ if(move_uploaded_file($_FILES['myfile']['tmp_name'][$i],$up_folder."/".$_FILES['myfile']['name'][$i])){ //成功上传后,计数器增 1 $up_ok_files +=1; } else{ echo "<h4 style='color:red;'>在服务器中保存失败</h4>"; } } } echo "<h4>成功上传 ".$up_ok_files. " 个文件</h4>"; }?> 如果对 $_FILES['myfile'] 这个数组的结构不清楚,那么可以在循环之前加入这句代码将其显示出来:print_r($_FILES['myfile']); 对这个数组的结构了解之后,理解上述代码就比较容易了。foreach循环实现常规下,php上传一张图片,页面上添加一个文件域,上传后,得到的数组是二维数组转变一下,页面上添加多个文件域,并且他们的name属性相同,而且是以数组形式提交(比如:name="file[]")那么上传后,得到的是三维数组而,php中,foreach循环对遍历数组那真是完美至极用foreach遍历一次这个三维数组,得到的结果就又是二维数组,那么,就和上传一张图片一样一样的了

Ⅵ 手机怎么把文件大量传到电脑上

数据线直接连接电脑,把他作为外部存储单元,在手机我的文档中查看,在设置中设定一下,可直接拷贝,也可以连接个外部存储卡或U盘

Ⅶ 几种js实现的动态多文件上传

方式一:事先写好多个input.在点击时才显示。也就是说上传的最大个数是写死了的。 html<p><a href='#' onclick='javascript:viewnone(more1)'> 添加附件 </a><div id='more1' style='display:none'> <input type="file" name="attach1" size="50"javascript:viewnone(more2)> </span></div><div id='more2' style='display:none'> <input type="file" name="attach2" size="50"'></div></p>js<SCRIPT language="javascript"> function viewnone(e){ e.style.display=(e.style.display=="none")?"":"none"; }</script>方式二:这种方式的动态多文件上传是实现了的,很简单的,不说废话看codehtml<input type="button" name="button" value="添加附件" onclick="addInput()"><input type="button" name="button" value="删除附件" onclick="deleteInput()"><span id="upload"></span>js<script type="text/javascript"> var attachname = "attach"; var i=1; function addInput(){ if(i>0){ var attach = attachname + i ; if(createInput(attach)) i=i+1; } } function deleteInput(){ if(i>1){ i=i-1; if(!removeInput()) i=i+1; } } function createInput(nm){ var aElement=document.createElement("input"); aElement.name=nm; aElement.id=nm; aElement.type="file"; aElement.size="50"; //aElement.value="thanks"; //aElement.onclick=Function("asdf()"); if(document.getElementById("upload").appendChild(aElement) == null) return false; return true; } function removeInput(nm){ var aElement = document.getElementById("upload"); if(aElement.removeChild(aElement.lastChild) == null) return false; return true; } </script>方式三:动态多文件上传,只是在oFileInput.click();这个地方,这样做就不能上传这个文件了,因为发现它在上传之时就把这个input中的文件置空了。很可能是为了安全着想吧!另外还有一点就是说,click()只有在ie中才能正常运行。虽说这种方式最终没能实现上传,但还是留下来参考,看看是否有人可以真正实现上传。 html<A href="javascript:newUpload();">添加附件</A><TABLE width="100%" border="0" cellpadding="0" cellspacing="1"> <TBODY id="fileList"></TBODY></TABLE><DIV id="uploadFiles" style="display:block"></DIV>js<SCRIPT language="javascript"> //—新建上传 function newUpload(){ var oFileList = document.getElementById("fileList"); var fileCount = oFileList.childNodes.length + 1; var oFileInput = newFileInput("upfile_" + fileCount); if(selectFile(oFileInput)){ addFile(oFileInput); } }//—-选择文件 function selectFile(oFileInput){ var oUploadFiles = document.getElementById("uploadFiles"); oUploadFiles.appendChild(oFileInput); oFileInput.focus(); oFileInput.click();//不能这样做,可能是为了安全着想吧! var fileValue = oFileInput.value; if(fileValue == ""){ oUploadFiles.removeChild(oFileInput); return false; } else return true; } //—新建一个文件显示列表 function addFile(oFileInput){ var oFileList = document.getElementById("fileList"); var fileIndex = oFileList.childNodes.length + 1; var oTR = document.createElement("TR"); var oTD1 = document.createElement("TD"); var oTD2 = document.createElement("TD"); oTR.setAttribute("id","file_" + fileIndex); oTR.setAttribute("bgcolor","#FFFFFF"); oTD1.setAttribute("width","6%"); oTD2.setAttribute("width","94%"); oTD2.setAttribute("align","left"); oTD2.innerText = oFileInput.value; oTD1.innerHTML = '<A href="javascript:removeFile('+ fileIndex + ');">删除</A>'; oTR.appendChild(oTD1); oTR.appendChild(oTD2); oFileList.appendChild(oTR); } //—移除上传的文件 function removeFile(fileIndex){ var oFileInput = document.getElementById("upfile_" + fileIndex); var oTR = document.getElementById("file_" + fileIndex); uploadFiles.removeChild(oFileInput); fileList.removeChild(oTR); } //—创建一个file input对象并返回 function newFileInput(_name){ var oFileInput = document.createElement("INPUT"); oFileInput.type = "file"; oFileInput.id = _name; oFileInput.name = _name; oFileInput.size="50"; //oFileInput.setAttribute("id",_name); //oFileInput.setAttribute("name",_name); //oFileInput.outerHTML = '<INPUT type=file id=' + _name + ' name=' + _name + '>'; //alert(oFileInput.outerHTML); return oFileInput; } </SCRIPT>

Ⅷ php如何实现一次性上传多个文件

<?php x0dx0a$max_files=5; //最多上传文件的个数,与 up.htm 中的 input file 控件的个数相同x0dx0a$up_ok_files=0; //成功上传的文件个数x0dx0a$up_folder="ups"; //保存上传文件的目标文件夹x0dx0aif(isset($_FILES[&#39myfile&#39])){x0dx0a //由于 $_FILES[&#39myfile&#39] 是个数组,所以需要使用循环遍历x0dx0a for($i=0;$i<$max_files;$i++){x0dx0a //如果未出错x0dx0a if($_FILES[&#39myfile&#39][&#39error&#39][$i]==0){x0dx0a if(move_uploaded_file($_FILES[&#39myfile&#39][&#39tmp_name&#39][$i],$up_folder."/".$_FILES[&#39myfile&#39][&#39name&#39][$i])){x0dx0a //成功上传后,计数器增 1x0dx0a $up_ok_files +=1;x0dx0a }x0dx0a else{x0dx0a echo "

在服务器中保存失败

“;x0dx0a }x0dx0a }x0dx0a }x0dx0a echo “

成功上启搏传 “.$up_ok_files. ” 个文件

“; x0dx0a}x0dx0a?>x0dx0ax0dx0a 如果对 $_FILES[&#39myfile&#39] 这个数组的结构不清楚,那么可以在循环之前加入这洞旁耐句代码将其显示出来:x0dx0aprint_r($_FILES[&#39myfile&#39]);x0dx0ax0dx0a 对这个数组的纳春结构了解之后,理解上述代码就比较容易了。x0dx0aforeach循环实现x0dx0a常规下,php上传一张图片,页面上添加一个文件域,上传后,得到的数组是二维数组x0dx0a转变一下,x0dx0a页面上添加多个文件域,并且他们的name属性相同,而且是以数组形式提交(比如:name=”file[]”)x0dx0a那么上传后,得到的是三维数组x0dx0a而,php中,foreach循环对遍历数组那真是完美至极x0dx0a用foreach遍历一次这个三维数组,得到的结果就又是二维数组,那么,就和上传一张图片一样一样的了

Ⅸ 如何通过js完成多个文件的上传

HTML5 file组件的新属性accept : 如果在file组件中增加这个属性就可以直接控制上传的文件类型了,实在是很方便。multiple:是否允许选择多个文件HTML5 页面代码修改后<img width="400" height="250"/><br /><input type="file" id="pic" name="pic" onchange="printFileInfo()" accept="image/*" multiple="multiple"/><input type="button" value="上传图片" onclick="uploadFile()" /><br /><div id="parent"><div id="son"></div></div>accept 的值可以参阅:IANA MIME 类型(标准 MIME 类型的完整列表),如果使用的是DW开发的话,软件本身就有提示。如果选择了多个文件,可以用JS做循环打印,看看文件的名称,类型和大小,看演示代码function printFileInfo(){var picFile = document.getElementById("pic");var files = picFile.files;for(var i=0; i<files.length; i++){var file = files[i];var div = document.createElement("div")div.innerHTML = "第("+ (i+1) +") 个文件的名字:"+ file.name +" , 文件类型:"+ file.type +" , 文件大小:"+ file.sizedocument.body.appendChild( div)}}既然可以循环多文件的话,就可以尝试多文件上传了。1、首先创建 XMLHttpRequest 对象//这是全局变量。因为是示例,所以就没有判断浏览器类型,低版本IE这么写的话会出问题的var xhr = new XMLHttpRequest()2、上篇介绍了进度事件(Progress) , 这次实现 progress 和 error 2个事件error:在请求发生错误时触发。对应上传时发生错误导致的上传失败:uploadFailed() //上传失败function uploadFailed(evt) {alert("上传失败");}progress:在接收相应期间持续不断触发。对应上传进度方法:onprogress()/*** 侦查附件上传情况 ,这个方法大概0.05-0.1秒执行一次*/function onprogress(evt){var loaded = evt.loaded; //已经上传大小情况var tot = evt.total; //附件总大小var per = Math.floor(100*loaded/tot); //已经上传的百分比$("#son").html( per +"%" );$("#son").css("width" , per +"%");}最后就是上传方法了,注意上面的html代码中上传用的方法也需要改成这个uploadFile()方法才能正常使用。//上传文件function uploadFile() {//将上传的多个文件放入formData中var picFileList = $("#pic").get(0).files;var formData = new FormData();for(var i=0; i< picFileList.length; i++){formData.append("file" , picFileList[i] );}//监听事件xhr.upload.addEventListener("progress", onprogress, false);xhr.addEventListener("error", uploadFailed, false);//发送文件和表单自定义参数xhr.open("POST", "upload");//记得加入上传数据formDataxhr.send(formData);}

Ⅹ 如何上传多个文件

很简单,你把要上传的文件全部用鼠标框起来,然后在随便一个选中的图标上点右键选择“添加到压缩文件”就可以了。还可以给你的压缩文件命名。


赞 (0)