当前位置: 移动技术网 > IT编程>开发语言>PHP > 一个多文件上传的例子(原创)

一个多文件上传的例子(原创)

2019年06月10日  | 移动技术网IT编程  | 我要评论

<?
//filename:multi_upload.php
if($ifupload)
{
  $path=addslashes(dirname($path_translated))."\\upload\\";
  for($i=1;$i<=8;$i++)
  {
     $files="afile".$i;
     if(${$files}!="none")
     {
        if(copy(${$files},$path.${$files."_name"}))
        {

        }
     }
   }
   print "<b>you have uploaded files successfully</b><br>";
   print "<a href=\"multi_upload.php\">return</a>";
   exit;
}
?>

<html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="generator" content="microsoft visual studio 6.0">
<title>多个文件上传</title>
<style type="text/css">
<!--
body
{
    padding-right: 0px;
    margin-top: 0px;
    padding-left: 0px;
    font-size: 8px;
    margin-left: 0px;
    cursor: default;
    color: black;
    margin-right: 0px;
    padding-top: 0px;
    font-family: arial;
    background-color: transparent;
    text-align: center
}
.txtinput
{
    font-size: 8pt;
    width: 100%;
    cursor: default;
    color: black;
    font-family: arial;
    height: 21px;
    background-color: white;
    text-align: left
}
.fieldlabel
{
    font-weight: normal;
    font-size: 9pt;
    width: 100%;
    color: black;
    font-family: arial;
    background-color: transparent;
    text-align: left
}
.headbtn
{
    border-right: black 1px solid;
    border-top: white 1px solid;
    font-size: 8pt;
    overflow: hidden;
    border-left: white 1px solid;
    width: 70px;
    color: black;
    border-bottom: black 1px solid;
    font-family: arial;
    height: 21px;
    background-color: #8e8dcd;
    text-align: center
}
.transex
{
    border-right: black 1px solid;
    padding-right: 8px;
    border-top: white 1px solid;
    padding-left: 8px;
    font-size: 8pt;
    padding-bottom: 3px;
    border-left: white 1px solid;
    width: 720px;
    padding-top: 3px;
    border-bottom: black 1px solid;
    font-family: arial;
    background-color: #c0c0c0;
    text-align: center
}
-->
</style>
<script language="javascript">
function window.onload()
{
    document.forms[0].btnok.onclick=btn_ok;
}
function btn_ok()
{
    for(var i=1;i<=8;i++)
    {
     if(eval("document.forms[0].afile"+i+".value!=''"))
       document.forms[0].submit();
      return true;
    }
    alert("none of file have been selected");
    return false;
}
</script>
</head>

<body>
<form method="post" action="multi_upload.php" name="frmupload" enctype="multipart/form-data" >
<table id="divcontainer" style="height: 100%; width: 380" border="0">
  <tr height="35"><td align="right" valign="bottom">多文件上传 </td></tr>
  <tr><td align="center" valign="top">

    <table class="transex" border="0" cellspacing="0" cellpadding="0" style="width: 360px">

    <tr style="height: 10px" >
        <td style="width: 5px"></td>
        <td colspan="2"></td>                
        <td style="width: 5px"></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件1</label></td>
        <td><input type="file" class="txtinput" tabindex="1" name="afile1"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件2</label></td>
        <td><input type="file" class="txtinput" tabindex="2" name="afile2" style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件3</label></td>
        <td><input type="file" class="txtinput" tabindex="3" name="afile3"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件4</label></td>
        <td><input type="file" class="txtinput" tabindex="4" name="afile4"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件5</label></td>
        <td><input type="file" class="txtinput" tabindex="5" name="afile5"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件6</label></td>
        <td><input type="file" class="txtinput" tabindex="6" name="afile6"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件7</label></td>
        <td><input type="file" class="txtinput" tabindex="7" name="afile7"  style="width: 282px"></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td nowrap><label class="fieldlabel">  文件8</label></td>
        <td><input type="file" class="txtinput" tabindex="8" name="afile8"   style="width: 282px"></td>
        <td></td>
    </tr>
    <tr style="height: 5px">
        <td style="width: 5px">
        <td style="width: 350px" colspan="2"><hr width="100%"></td>                
        <td style="width: 5px"></td>
    </tr>
    <tr>
        <td></td>
        <td colspan="2" align="left">
            <button tabindex="5" class="headbtn" align="center" name="btnok" id="btnok" accesskey="o">确定(<ins>o</ins>)</button>
            <input type="hidden" name="ifupload" value=1>
            <button tabindex="5" class="headbtn" align="center" name="btncancel" id="btncancel" accesskey="c" onclick="window.close();">取消(<ins>c</ins>)</button></td>    
        <td></td>
    </tr>
    <tr style="height: 5px">
        <td style="width: 5px">
        <td style="width: 350px" colspan="2"></td>                
        <td style="width: 5px"></td>
    </tr>
    </table>
  </td>
  </tr>
</table>
</form>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网