开发者

Form input to select multiple files to save as array

Newbie question - Not sure if this is a html or php question.开发者_StackOverflow I would like to create a form that would allow multiple files to be selected to be later posted as an array. Is this possible with a different type of type="file" to allow more than one file?


If you are looking for a multiple file uploader, then try this.

<?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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜