php://input is empty on POST request

14,828

Before PHP 5.4 $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data" (with the exception of some SAPI implementations), explanations here:

I suggest you give a look to a couple of answers to existing questions:

From PHP 5.4+ you can use the php.ini directive enable_post_data_reading to disable PHP consuming the raw data (hence process it), be aware that $_POST and $_FILES won't be populated though (refer to Vitaly Chirkov answer).

Share:
14,828
Vitaly Chirkov
Author by

Vitaly Chirkov

My interests are PHP, Python, NoSQL storages (Cassandra, MongoDB, Redis), high load and big data, OOP, testing, DDD.

Updated on June 25, 2022

Comments

  • Vitaly Chirkov
    Vitaly Chirkov almost 2 years

    Problems with multipart/form-data forced me to parse POST request's parameters manually as I already doing for PUT requests. For that purpose I used this code:

    $rawData = file_get_contents('php://input');
    

    But I figured that php://input is always empty for POSTs, at least, for php-fpm SAPI.

    Here is some pics from debugger. POST request:

    empty $rawData

    PUT with same params:

    filled $rawData

    Is there a way to get raw POST request body? Thanks in advance.

  • David Riccitelli
    David Riccitelli over 10 years
    That wouldn't work $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data": php.net/manual/en/…
  • Bas Kuis
    Bas Kuis over 10 years
    Looks like: php://input is not available with enctype="multipart/form-data" also php.net/manual/en/wrappers.php