0

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/>
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Paras Dalsaniya
  • 99
  • 2
  • 10
  • You're missing the `multiple` property. And I don't think you can do it without JS and if you re-consider, there's a [question](http://stackoverflow.com/questions/10105411/how-to-limit-maximum-items-on-a-multiple-input-input-type-file-multiple) that might help your through jQuery. – al'ein Sep 03 '15 at 10:41

2 Answers2

0

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;
    }
});
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
0

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.

al'ein
  • 1,711
  • 1
  • 14
  • 21