Count and limit the number of files uploaded (HTML file input)

You can implement a javascript solution to check the number of files that have been selected, which you can then use to forbid uploading to the server. There are really only going to be client-side solutions to this problem though, as there is really nothing stopping a user from posting these files to your php script anyway. You can specify a maximum upload size limit, but it isn’t specific to the number of files that are being uploaded.

Your best bet is to implement some javascript checking, specifying a reasonable maximum upload size for your http server (or in PHP), and then ignoring any file uploaded if it exceeds your maximum count.

Read about the HTML5 File API here to restrict the count of selected files: http://dev.w3.org/2006/webapi/FileAPI/

Here is the php.ini docs which explain how to make a size limitation on uploads: http://php.net/manual/en/ini.core.php

As was suggested in the comments, check out: http://php.net/manual/en/ini.core.php#ini.max-file-uploads

Leave a Comment