我应该在循环中使用文件上传,例如,
<form action="upload.php" method="post" enctype="multipart/form-data" name="form1"  id="form1"onsubmit="return(validate());">   
<?php for($i=0;$i<3;$i++)?>
<?php {?>
Select file:
<input name="ufile[]" type="file" id="file<?=$i;?>" size="50" />
<?php }?>
<input type="hidden" name="ivalue" value="3" id="someVar"/>
<input type="submit" name="Submit" value="Upload" />
</form>
我已经对文件上传进行了一些验证。喜欢,
<script type="text/javascript">
function validate()
{
var x=document.getElementById("someVar").value;
      for(i=0;i<x;i++) 
    {
     var filename=document.getElementById('file'+i).value;
     var extension=filename.substr(filename.lastIndexOf('.')+1).toLowerCase();
     if(filename)
     {
         if(extension=='png' || extension=='gif' || extension=='jpg' ||extension=='jpeg') {
                return true;
            } else {
                alert('Allowed Extensions are "png","gif" and "jpg" !');
                return false;
            }
         return true;
     }
     else
     {
         alert('Select upload files!');
         return false;
     }
    }
  }
</script>
但我的脚本仅验证第一个文件。(我知道这是由于 id 命名约定)。但是我需要验证,如果用户没有选择任何文件。我该怎么做?我的意思是,如何将所有文件的验证放在 for 循环中?
谢谢!