多文件上传的例子

2015-01-24信息快讯网

多文件上传的例子//upload_html.php---------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>上传文件</TITLE>
</HEAD>
<script>
function beforesubmit(forma)
{
   var indexnamea=forma.indexname.value;
   var upfilea=forma.upfile.value;
   var k=/ /g;
   var indexnamea=indexnamea.replace(k,"");
   var upfilea=upfilea.replace(k,"");
   if(indexnamea==""
upfilea=="")
   {
      alert("目录名称或上传的目录不能为空!");
      return false;
   }
   return true;
}
</script>
<BODY BGCOLOR=WHITE>
<BR>
<form name=form1 action="upload.php" method=post enctype=\"multipart/form-data\" >\n";
<table cellspacing="1" cellpadding="5" border="0" width="580" bgcolor="#C2E2F5">
  <tr bgcolor="#E3F2FB" align="center">  
    <td width="280" align="center" height="30">上传的文件</td>
  </tr>
<?
for($i=1;$i<8;$i++)   
{
  $upfile="upfile".strval($i);
  echo "  <tr>\n";  
  echo "     <td bgcolor=#F5FBFE width=264><input type=file name=$upfile lengh=25></td>\n";
  echo "  </tr>\n";  
}
?>
  <tr bgcolor="#E3F2FB">
    <td colspan="2" height="1">  
    </td>
    <td colspan="2" height="1">  
      <div align="center">
        <input type=submit name="submit" value=上传>
      </div>
    </td>
</table>
</form>
</body></html>
//-----------------------------------------------------------------------------------------------------------------------

//upload.php-------------------------------------------------------------------------------------------------------------
//upload_path:文件要上传到的目录路径
<?php
for($i=1;$i<8;$i++)
{
   $upfile="upfile".strval($i);
   if(chop($$indexname)!="" and chop($$upfile)!="")
   {
      $upfilename=($upfile."_name");
      $filename=upload_path.$$upfilename;
      $copyfile = copy($$upfile,$filename);     
      if (!$copyfile)
         die("文件上传失败!");  
      $ls_file.=$$upfilename."\n";
      $flag=1 ;   
   }
}  
if($flag){      
  $ls_msg="文件\n".$ls_file."上传成功!";  
}
else{
  $ls_msg="无文件上传,请重新选择!";
}   
     echo "<HTML>\n" ;  
     echo "<HEAD>\n" ;
     echo "</HEAD>\n" ;
     echo "<BODY >\n" ;
     echo $ls_msg."\n";
     echo "</BODY>\n" ;
     echo "</HTML>\n" ;
?>
©2014-2024 dbsqp.com