Alternative way to read source input / output stream in PHP

I am trying to find an alternative to reading php: // input. I use this to get XML data from CURL PUT.

I usually do this with:

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

However, I have a few problems with file_get_contents() on Windows.

Is there an alternative, possibly using fopen() or fread() ?

+4
source share
2 answers

Yes you can do:

 $f = fopen('php://input', 'r'); if (!$f) die("Couldn't open input stream\n"); $data = ''; while ($buffer = fread($f, 8192)) $data .= $buffer; fclose($f); 

But the question you need to ask yourself is why is file_get_contents working on windows? Because if it does not work, I doubt that fopen will work for a single thread ...

+1
source

Ok I think I found a solution.

 $f = @fopen("php://input", "r"); $file_data_str = stream_get_contents($f); fclose($f); 

Also, with this I am not required to enter the file size.

0
source

Source: https://habr.com/ru/post/1338110/


All Articles