php - 在 PHP 中读取原始 I/O 流的替代方法

标签 php file-io io

我正在尝试寻找一种替代方法来读取 php://input。我用它从 CURL PUT 中获取 XML 数据。

我通常这样做:

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

但是,我在 Windows 上使用 file_get_contents() 时遇到了一些问题。

是否有替代方案,也许使用 fopen()fread()

最佳答案

是的,你可以这样做:

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

但是,您必须问自己的问题是,为什么 file_get_contents 不能在 Windows 上运行?因为如果它不起作用,我怀疑 fopen 是否适用于相同的流...

关于php - 在 PHP 中读取原始 I/O 流的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4876056/

相关文章:

arrays - Haskell 可变结构与不可变 Shell

php - 为什么如果我不在表单末尾放置 {{csrf_field()}} (在 Laravel 5 View 中),我会收到 TokenMismatchException?

php - 如何在ArrayHelper Yii2中传递两个不同的查询数据?

c# - 'the requested operation cannot be performed on a file with a user-mapped section open?' 时出了什么问题

python - Unicode解码错误: 'ascii' codec can't decode byte 0xc3 in position 40: ordinal not in range(128)

c# - 如何等待文件完全复制?

PHP 搜索引擎无法运行?

php - 索引列但保持快速插入

io - FORTH 包括与负载?

Linux 输出到文本文件