3

I'm putting two questions in this "Question"...

1) First of all, I have a <input type="file" name="file[]" multiple="multiple" />, Now I can select as many images as I want, but I need to limit this number to 10 maximally. How would I do this?

2) What would my upload.php file look like to handle multiple uploaded images? I never had the chance to work on anything more than single image uploading, but now I'm stuck at this and I need this. I'm quite confused...

Help please?

aborted
  • 4,481
  • 14
  • 69
  • 132

3 Answers3

4

1 You could use javascript to detect the number of files selected, and give a warning if it's more than 10

$('fileinput').onchange=function(){if(this.files.length>10)alert('to many files')}
//prevent submitting if to many
$('form').onsubmit=function(){if(this.files.length>10)return false;}

you could even check if the combined filesize isn't to big by adding up all .files[i].fileSize

2 see: http://php.net/manual/en/features.file-upload.multiple.php (short version; use: $_FILES['userfile']['name'][0], $_FILES['userfile']['tmp_name'][0], $_FILES['userfile']['size'][0], and $_FILES['userfile']['type'][0])

Gerben
  • 16,747
  • 6
  • 37
  • 56
0

I have already given an answer

so i am writing only the code part here

if(empty($_FILES['file']['name'][0]))
{
     //checking whether a single file uploaded or not
     //if enters here means no file uploaded
}
if(isset($_FILES['file']['name'][10]))
{
     //checking whether 11 files uploaded or not
     //so here you can restrict user from uploading more than 10 files
}
Community
  • 1
  • 1
RbG
  • 3,181
  • 3
  • 32
  • 43
0

For the front-end, you should also consider using file upload libraries: they allow limiting and much more:

They are also available at https://cdnjs.com/

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985