zoukankan      html  css  js  c++  java
  • 多附件上传

     2012-03-18
    <script>
                 function AddAttachments()
                 {
                       document.getElementById('attach').innerText = "继续添加附件";
                      
                       tb = document.getElementById('attAchments');                  
                       newRow = tb.insertRow();
                       newRow.insertCell().innerHTML = "<input name='File' size='50' type='file'>   <input type=button value='删除' onclick='delFile(this.parentElement.parentElement.rowIndex)'>";
                 }
                 function delFile(index)
                 {
                       document.getElementById('attAchments').deleteRow(index);
                       tb.rows.length > 0?document.getElementById('attach').innerText = "继续添加附件":document.getElementById('attach').innerText = "添加附件";
                 }
                 </script>
    
    
    <TR id="tr2" runat="server">
                                      <TD style="BORDER-BOTTOM: #c1c1c1 1px solid" 
                                    height=30>
                                        <DIV align=right><FONT 
                                    color=#666666><strong>上传附件:</strong> </FONT></DIV></TD>
                                 <TD style="BORDER-BOTTOM: #c1c1c1 1px solid">
                                       <div><table id="attAchments"></table></div><span></span> 
                        
      <A id="attach" style="font-family:宋体;font-size:9pt;" title="如果您要发送多个附件,您只需多次点击“继续添加附件”即可, 要注意附件总量不能超过发送限制的大小。" onclick="AddAttachments();"
                             href="javascript:;" name="attach">添加附件</A> 
    
    <font color="red">(请上传附件,只能上传.doc,docx)</font>
                             
            </TD>
        </TR>
         //上传附件
                string filePath = "";
                string traget = "";
                string[] files = new string[Request.Files.Count];         
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    if (Request.Files[i].ContentLength > 0)
                    {
                        filePath = Request.Files[i].FileName;//上传的原地址
    
                        if (System.IO.Path.GetExtension(filePath).ToString().ToLower() == ".doc" || System.IO.Path.GetExtension(filePath).ToString().ToLower() == ".docx")
                        {
                            traget = Server.MapPath("../upload/") + filePath.Substring(filePath.LastIndexOf("\\") + 1);
    
                            if (File.Exists(traget))
                            {
                                Thread.Sleep(10);
                                Random ran = new Random();
    
                                traget = Server.MapPath("../upload/") + filePath.Substring(filePath.LastIndexOf("\\") + 1).Replace(".", System.DateTime.Now.ToString("yyyyMMddhhmmssms") + ran.Next(1000).ToString() + ".");
                            }
                            files[i] = traget;
    
                            File.Copy(filePath, traget);
                        }
                        else 
                        {
                           // Response.Write("");
                            this.Page.RegisterStartupScript("", "<script>alert('只能上传doc或是.docx文件!');</script>");
                            return;
                        }   
                    }
                }
    
                for (int j = 0; j < files.Length; j++)
                {
                    orderServiceListBLL.Insert(OrderSerid, ServiceType, userCode, orderDate, address, zipCode, phoneNumBer, realName, fax, unitName, ProvisionDate,      OrderState, files[j], note, addPrice, p);
                }
    

      

  • 相关阅读:
    记录一次SpringCloud Alibaba整合Springboot出现的'com.netflix.client.config.IClientConfig' that could not be found
    ysoserial-URLDNS链分析
    DIVA闯关-APP测试
    前端页面直接转换为PDF文件流
    中位数最大问题
    【vim】Linux添加环境变量等
    FFmpeg使用笔记
    【memo】及时留坑
    【album】深度学习 / 机器学习 / 人工智能
    【Linux】软件安装使用【aubio / FFmpeg】
  • 原文地址:https://www.cnblogs.com/zmmlczy/p/2405044.html
Copyright © 2011-2022 走看看