#13: Preventing Users from Uploading Large Files

If you want to keep your users from uploading 70GB MPEGs of the latest Star Wars movie, you can set a maximum file size when users are uploading files to your server. (For information on how to process uploaded files, see "#54: Uploading Images to a Directory" on #54: Uploading Images to a Directory.)

upload_max_filesize = 500K

You can specify the maximum file size in one of three ways:

  • An integer (indicating the total number of bytes)

  • Using a number and an M to indicate megabytes, as in 2M (2 megabytes)

  • Using a number and a K to indicate kilobytes, as in 8K (8 kilobytes)

In any case, your users will now be unable to upload anything greater than the size you set. The default is 2MB.

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.