1

I started working with multiple images uploading. You open the select file window and you select files while holding CTRL to select multiple files. I got everything to work except a part:

I cannot limit the file size for one image! I cannot figure out how to grab one of the images and compare it with my desired file size (10 MB), if the file size is bigger than 10 MB the user should receive an error, if it's lesser than 10 MB, then continue..

How would I do this? It's quite different with multiple files, not the same as with one file.

aborted
  • 4,481
  • 14
  • 69
  • 132
  • 1
    Which client-side technology / framework are you using to make multi-file upload possible with CTRL+click selecting multiple files? Sounds like flash to me, but you didn't say anything about that in your question. – hakre Jul 04 '11 at 12:43
  • It's HTML 5. I simply used the multiple="multiple" attribute. – aborted Jul 04 '11 at 13:00
  • 1
    possible duplicate of [Client Checking file size using HTML5?](http://stackoverflow.com/questions/4112575/client-checking-file-size-using-html5) - [ref4linked](http://stackoverflow.com/questions/4112575/client-checking-file-size-using-html5) - You need to use javascript to do that client-side. – hakre Jul 04 '11 at 13:02
  • Another Related: [Detecting file upload size on the client side?](http://stackoverflow.com/questions/2934788/detecting-file-upload-size-on-the-client-side) – hakre Jul 04 '11 at 13:04
  • Check the referenced questions / answers, should have very useful information for you. – hakre Jul 04 '11 at 13:06

3 Answers3

3

Okay, I figured out how to fix this issue the following way. I used a foreach loop for uploading multiple images. I used it this way:

foreach ($_FILES['file']['tmp_name'] as $key => $tmp_name) 

Inside the loop I did the following:

$fileSize = $_FILES['file']['size'][$key];

if ($fileSize <= 10485760)
{
       // upload code
}

This got this to work ! :D

Hope thi serves anyone in the future...

aborted
  • 4,481
  • 14
  • 69
  • 132
1

in php there is standard mechanism that allow to limit fize of uploading files. you just need to add form parmeter MAX_FILE_SIZE and specify size it bytes as its value:

<form method="post" enctype="multipart/form-data">
 <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
 <input type="file" name="excel_file"/>
</form>
heximal
  • 10,327
  • 5
  • 46
  • 69
  • I tried this one, and I received a 45.5 Megabytes image in my server with a small delay, but it's there :\ – aborted Jul 04 '11 at 12:59
1

i would recommend taking all the files as an array and then checking for size on each of them, also keep in mind that you should set a max of the number of files that can be uploaded by 1 person at 1 time.

Shapsough
  • 11
  • 1