Search code examples
phpnginxfpm

php-fpm: Some POST data missing when uploading a file


I'm using PHP 7.2 fpm with nginx on an Ubuntu 18.04 machine and I'm having a problem with form data getting lost. The form submits data roughly in this structure:

[
'video' => [
    'translations' => [
        'de' => [
            'title' => 'string',
            'subtitles' => 'upload field'
        ]
    ],
    'posterFrame' => 'upload field'
    'duration' => 'string'
]]

When I leave the upload fields empty, the entire form data is available correctly in $_POST. However, when I try to upload a file (10 kB in size) in the posterFrame field, it shows up as expected in $_FILES, but $_POST then only contains the keys that were listed before the upload field, i.e. in the example, translations is available in $_POST, but duration is missing (I also checked php://input, which is empty).

All the relevant php.ini settings (max_post_size, allow_file_uploads etc.) look fine, and the application code itself also seems ok, at least it works on a different 18.04 machine (with Apache/mod_php), so I'm at a loss as to what might be the problem here. The nginx vhost config is straight from the Symfony documentation, and php-fpm config is what shipped with Ubuntu. There's nothing in any of the error logs I checked (php-errors, syslog, nginx/error.log etc). What could have gone wrong here?

EDIT: There is one thing I just noticed: When I post the form, I get these lines in nginx/access.log:

[my client ip] - - [16/May/2018:14:56:52 +0000] "POST /backend/videos/edit/1162214/ HTTP/1.1" 500 11373 "http://[myserver]/backend/videos/edit/1162214/" "Mozilla/5.0"
[my client ip] - - [16/May/2018:14:56:52 +0000] "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\xE1I%Exif\x00\x00II*\x00\x08\x00\x00\x00\x09\x00\x0F\x01\x02\x00\x06\x00\x00\x00z\x00\x00\x00\x10\x01\x02\x00\x0E\x00\x00\x00\x80\x00\x00\x00\x12\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x1A\x01\x05\x00\x01\x00\x00\x00\xA0\x00\x00\x00\x1B\x01\x05\x00\x01\x00\x00\x00\xA8\x00\x00\x00(\x01\x03\x00\x01\x00\x00\x00\x02\x00s32\x01\x02\x00\x14\x00\x00\x00\xB0\x00\x00\x00\x13\x02\x03\x00\x01\x00\x00\x00\x02\x003si\x87\x04\x00\x01\x00\x00\x00\xC4\x00\x00\x00X$\x00\x00Canon\x00Canon EOS 20D\x0033\x7F\xFF\xF5\xBB3333\xB7\xF7\xBF;\xB3;33H\x00\x00\x00\x01\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x002018:05:06 18:33:31\x00\x1C\x00\x9A\x82\x05\x00\x01\x00\x00\x00\x1A\x02\x00\x00\x9D\x82\x05\x00\x01\x00\x00\x00\x22\x02\x00\x00\x22\x88\x03\x00\x01\x00\x00\x00\x02\x0073'\x88\x03\x00\x01\x00\x00\x00@\x06\xCC\xCC\x00\x90\x07\x00\x04\x00\x00\x000221\x03\x90\x02\x00\x14\x00\x00\x00*\x02\x00\x00\x04\x90\x02\x00\x14\x00\x00\x00>\x02\x00\x00\x01\x91\x07\x00\x04\x00\x00\x00\x01\x02\x03\x00\x01\x92" 400 182 "-" "-"

So at first glance I would say that this is the binary data of the image that somehow ends up in the request URL? How can that happen?


Solution

  • ok, after converting the setup to Apache/mod_php I noticed that the GD extension was not installed on this machine (got a Call to undefined method imagecreatefromjepg in the log). I installed GD, and now it works properly. No idea why php-fpm swallowed the error and produced such strange behavior in nginx though