views:

225

answers:

2

I receive POST request on my api.php script. The content red using this code:

    $fp = fopen('php://stdin', 'r');
    $all = "";
    while($line = fgets($fp, 4096)) 
    { 
      $all .= $line; 
    }
    echo $all;

looks like this:

------------V2ymHFg03ehbqgZCaKO6jy
Content-Disposition: form-data; name="intro"

O
------------V2ymHFg03ehbqgZCaKO6jy
Content-Disposition: form-data; name="title"

T
------------V2ymHFg03ehbqgZCaKO6jy
Content-Disposition: form-data; name="apiKey"

98d32fdsa
------------V2ymHFg03ehbqgZCaKO6jy
Content-Disposition: form-data; name="method"

/media/add
------------V2ymHFg03ehbqgZCaKO6jy
Content-Disposition: form-data; name="upload_field"; filename="original_filename.png"
Content-Type: image/png


------------V2ymHFg03ehbqgZCaKO6jy--

As you can see I get 4 parameters called intro, title, apiKey and method, and one file called original_filename.png with size of 1460 bytes.

Unfortunately, my $_POST array is empty. What is weird when orginal_filename.png is less than 1450 bytes $_POST contains all parameters, and stdin is empty.

I would like to be able to read these fields like normal human PHP being from $_POST.

What to do in order to read this POST request parameters properly from $_POST?

+1  A: 

As I just read in the manual, raw post data is not available with enctype="multipart/form-data" but can you can also try with

$fp = fopen('php://stdin', 'rb');

Please pay attention to the "b" flag.

Also, make sure that always_populate_post_data=On in your php.ini

narcisradu
??? You wrote first line of source code that I put in my question. It's not very helpfull...
tomaszs
Please pay attention to the flags! I wrote rb not only r!
narcisradu
@narcisradu Ok, thanks, i understand that this is a fix of a error in my code above , ok. I appreciate it , but still hope to find a solution for the main issue here. Kind regards!
tomaszs
+1  A: 

Is there anything in the $_FILES variable?

Is there a MAX_FILE_SIZE element in the submitted form?

What are the values here?

echo 'post_max_size = ' . ini_get('post_max_size') . "\n";
echo 'upload_max_filesize = ' . ini_get('upload_max_filesize') . "\n";
pferate
These parameters are 16M. In FILES there is no data at all
tomaszs
Are the files being uploaded from a form on the previous page or some other way? If there's a form, can you post the relevant source for it?
pferate