php://input & php://output 是什么意思,什么时候需要用到?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7186189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of php://input & php://output and when it needs to use?
提问by Rahul
What is the meaning of php://input
& php://output
and when it needs to use?
Please explain with an example.
php://input
&的含义是什么,什么php://output
时候需要使用?请举例说明。
回答by Bailey Parker
These are two of the streamsthat PHP provides. Streams can be used by functions like fopen, fwrite, stream_get_contents, etc.
这是PHP 提供的两个流。流可以被fopen、fwrite、stream_get_contents等函数使用。
php://input
is a read-only stream that allows you to read the request body sent to it (like uploaded files or POST variables).
php://input
是一个只读流,允许您读取发送给它的请求正文(如上传的文件或 POST 变量)。
$request_body = stream_get_contents('php://input');
php://output
is a writable stream that is sent to the server and will be returned to the browser that requested your page.
php://output
是发送到服务器的可写流,并将返回到请求您的页面的浏览器。
$fp = fopen('php://output', 'w');
fwrite($fp, 'Hello World!'); //User will see Hello World!
fclose($fp);
Note that if you are in the CLI, php://output will write data to the command line.
请注意,如果您在 CLI 中,php://output 会将数据写入命令行。
回答by Pekka
The PHP manualhas a good explanation and examples.
在PHP手册中有一个很好的解释和例子。
If you have trouble understanding something that is said there, feel free to ask again specifically - the more detailed the question, the better it is usually received.
如果您无法理解那里所说的内容,请随时具体询问 - 问题越详细,通常收到的效果就越好。