# Unable to access HTTP PUT data in webservice code

All,

As part of an application I'm writing I need to have a HTTP PUT webservice which accepts incoming imagedata, which will by analyzed, validated, and added to a local file store.

My issue arises after the size validation as the

$_SERVER['CONTENT_LENGTH'] has a > 0 value, and this value is identical to the test file size, so I can assume that all is going well up to this point but when I try to read the incoming stream data using file_get_contents('php://stdin'); I get an empty string. I've also tried using file_get_contents('php://input'); And this give me the same result of an empty string. Any help, suggestions or direction will be appreciated. NB: I'm using • PHP 5.2.6 • Apache 2.0 2 2022-07-25 20:41:54 Source Share Answers: 2 file_get_contents does not take the "r" parameter - see : string file_get_contents ( string$filename  [, int $flags...)  Valid $flag values are FILE_USE_INCLUDE_PATH, FILE_TEXT, FILE_BINARY.

Attempt getting rid of the "r" flag and also attempting once more

Edit - inquiry upgraded, "r" flag was being overlooked so seemingly not the origin of the trouble.

It resembles there is a pertaining to file_get_contents returning a vacant string for a HTTP POST. From the bug description:

file_get_contents('php://input') (as well as additionally file, fopen+fread) does not return POST information, when sent kind with enctype = "multipart/form - data".

When sent the very same kind without enctype defined (so default "application/x - www - kind - urlencoded" is made use of) all jobs OK.

So it resembles a job - around is to transform the specific kind enctype far from multipart/form-data, which clearly isn't excellent for a photo upload - from the :

The web content type "application/x - www - kind - urlencoded" mishandles for sending out huge amounts of binary information or message having non - ASCII personalities. The web content type "multipart/form - data" need to be made use of for sending kinds which contain documents, non - ASCII information, and also binary information.

More Edit

This bug appears to have actually been settled in your PHP variation. Have you examined to see to it that the barrier reading in does not start with a carriage - return / newline char? There is a trouble rather comparable to your own that was reviewed .

Attempt running on the input and also see what the size is.

0
2022-07-25 22:05:27
Source

The r you've obtained as the 2nd arg isn't right. file_get_contents does not make use of the a/r/w/a+/r+/w+ debates that fopen usages. You possibly intend to remove it and also simply do:

file_get_contents('php://input');


See .

0
2022-07-25 22:03:20
Source