PHP File Uploads

Yesterday at work I spent the better part of the afternoon trying to figure out why a form couldn’t handle multiple file uploads. These uploads where failry big – quicktime and wmv files – so I thought the culprit was the large file size. But the script was not returning any error warnings or notices which made it quite a pain to debug. With a co-workers help we traced it to two settings in php.ini.

  • post_max_size = (some number)M
  • upload_max_filesize = (some number)M

post_max_size controls the total size of your post request while upload_max_filesize controls the max size of each file uploaded. The sum of file sizes can’t exceed the maximum size of the post request.

A related apache setting could come in to play here, LimitRequestBody, which also sets a limit on how large a post request can be. So, in order to have working uploads for your php scripts, these 3 numbers have to jive. LimitRequestBody = post_max_size >>> upload_max_filesize