I need to select the limited file from the open input type file popup. I don't want to used validation like jquery or javascript.
<input type="file" name="question_pic" id="id_question_pic" max-uploads = 6/>
I need to select the limited file from the open input type file popup. I don't want to used validation like jquery or javascript.
<input type="file" name="question_pic" id="id_question_pic" max-uploads = 6/>
You can use Jquery to limit the no. of files upload:
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;
}
});
Since you don't want to do client-side validation and tagged your question with PHP, you must do it server-side. But then, remind that you'll only have answer to your request once the HTTP REQUEST is complete (after uploading the files to transfer).
HTML
<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: if you don't want to do it server-side neither, then there is no way.