在打开的弹出窗口中选择输入类型文件中的有限文件


Select limited file in input type file in open popup

我需要从打开的输入类型文件弹出框中选择有限的文件。我不想使用像jquery或javascript那样的验证。

<input type="file" name="question_pic" id="id_question_pic" max-uploads = 6/>

您可以使用Jquery来限制no。文件上传:

HTML

<input type="file" name="question_pic" id="id_question_pic" multiple max-uploads = 6/>
Jquery

var noOfUploads;
$("#id_question_pic").change(function() {
    if(noOfUploads > $(this).attr(max-uploads))
    {
    alert('Only '+$(this).attr(max-uploads)+' uploads Allowed');
    }
    else
    {
    noOfUploads = noOfUploads + 1;
    }
});

由于您不想进行客户端验证并使用PHP标记您的问题,因此必须执行服务器端。但是,请记住,只有在HTTP请求完成后(在上传要传输的文件之后),您才能得到请求的答案。

<input type="file" name="question_pic[]" id="id_question_pic" multiple>
PHP

if (count($_REQUEST['question_pic']) > 6) {
    echo "You can't upload more than 6 files";
    // other error dealing code
} else {
    echo "Upload ok!";
    // other after-upload dealing code
}

OBS: there is no HTML5 native property for input type=file named max-uploads .

OBS2:如果您也不想在服务器端这样做,那么就没有办法了。