file_get_contents
doesn't take the "r" parameter - see the PHP manual page:
string file_get_contents ( string $filename [, int $flags...)
Valid $flag
values are FILE_USE_INCLUDE_PATH, FILE_TEXT, FILE_BINARY
.
Try removing the "r" flag and trying again
Edit - question updated, "r" flag was being ignored so evidently not the root of the problem.
It looks like there's a reported bug in PHP regarding file_get_contents
returning an empty string for a HTTP POST. From the bug description:
file_get_contents('php://input')
(and also file, fopen+fread
) does not
return POST data, when submited form with
enctype="multipart/form-data".
When submited the same form without enctype specified (so default
"application/x-www-form-urlencoded" is used) all works OK.
So it looks like a work-around is to change the specified form enctype away from multipart/form-data
, which obviously isn't ideal for an image upload - from the W3 FORM specification:
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
Further Edit
This bug seems to have been resolved in your PHP version. Have you checked to make sure that the buffer being read in doesn't start with a carriage-return / newline char? There's a problem somewhat similar to yours that was discussed on Sitepoint.
Try running strlen
on the input and see what the length is.