15

I'm trying to allow users to upload large files (64MB) and am planning to change upload_max_filesize to 64MB.

However, should I also change memory_limit to 64MB or larger?

Is memory_limit connected to upload_max_filesize?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
tzmatt7447
  • 2,329
  • 9
  • 24
  • 31

2 Answers2

17

No, it's not necessary.

PHP has different POST readers and handlers depending on the content type of the request. In case of "multipart/form-data" (what is used for sending files), rfc1867_post_handler acts as a mixed reader/handler. It populates both $_POST and $_FILES. What goes into $_POST counts towards the memory limit, what goes into $_FILES also counts.

However, $_FILES has just meta-data about the files, not the files themselves. Those are just written into the disk and hence don't count towards the memory limit.

Artefacto
  • 96,375
  • 17
  • 202
  • 225
10

post_max_size must be bigger than upload_max_filesize. If a form contains more file uploads then the post_max_size must be greater than the sum of them.

The memory_limit does not have any significant role in file uploads, as uploaded files are stored in the /tmp (Linux) directory, not in memory. If you want to submit large amount of data with form fields (not file uploads) then you need a big memory_limit otherwise not.

Notinlist
  • 16,144
  • 10
  • 57
  • 99