表单输入以选择多个文件以保存为数组

时间:2011-01-23 08:52:20

标签: php html

新手问题 - 不确定这是html还是php问题。我想创建一个表单,允许选择多个文件以便稍后作为数组发布。这是否可以使用不同类型的type =“file”来允许多个文件?

1 个答案:

答案 0 :(得分:0)

如果您正在寻找多文件上传器,请尝试此操作。

<?php
if(isset($_POST['btn_upload'])){
    $limit=count($_FILES['uploads']['name']);
    $success=$fail=0;
    for($i=0;$i<$limit;$i++){
        if(move_uploaded_file($_FILES['uploads']['tmp_name'][$i],
                              "uploads/".$_FILES['uploads']['name'][$i])){
            $success++;
        }
        else{
            $fail++;
        }
    }
    if($success>0){
        echo "Successfully uploaded ".$success." files";    
    }
    if($fail>0){
        echo "uploading of ".$fail." files failed";
    }
}
?>
<html>
<head>
<title></title>
</head>
<body>
    <frameset style="width:30%">
        <legend>Multiple Upload</legend>
        <form name="multipleUpload" id="" action="" method="POST"
              enctype='multipart/form-data'>
            <input type='file' id='uploadFile' name='uploads[]' multiple=""/>
            <input type='submit' value='upload' name='btn_upload'/>
        </form>
    </frameset>
</body>
</html>