在PHP中读取原始I / O流的替代方法 [英] Alternative way to read raw I/O stream in PHP

查看:129
本文介绍了在PHP中读取原始I / O流的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个替代阅读php://输入。我使用这个从CURL PUT获取XML数据。



我通常这样做:

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

然而,我遇到了一些与 file_get_contents()

是否有替代方案,可能使用 fopen() fread()

解决方案

是的,您可以这样做: b
$ b

  $ f = fopen('php:// input','r'); 
if(!$ f)die(Could not open input stream \\\
);
$ data ='';
while($ buffer = fread($ f,8192))$ data。= $ buffer;
fclose($ f);

但是,您必须问自己的问题是为什么不是 file_get_contents 在Windows上工作?因为如果它不工作,我怀疑 fopen 可以用于同一个流...


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

I usually do this with:

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

However, I'm having a few issues with file_get_contents() on Windows.

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

解决方案

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 have to ask yourself is why isn't file_get_contents working on windows? Because if it's not working, I doubt fopen would work for the same stream...

这篇关于在PHP中读取原始I / O流的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆